Page 1 of 1

Time Series exercise

PostPosted: Tue Mar 21, 2017 8:22 am
by wjgatt
This is probably a stupid question. I am trying to run the example code on the dynare manual pg 122, which shows the filtered series using the Baxter-King band pass filter.

My question is, is that example complete? I.e. do you just create a mod file with just those lines and run it through dynare? When I do so dynare crashes with the following error message:

Code: Select all
ERROR: ts_model.mod: line 21, col 1 - line 28, col 0: syntax error, unexpected $end


Could anyone clarify this please?

Thanks
Will

Re: Time Series exercise

PostPosted: Tue Mar 21, 2017 8:44 am
by jpfeifer
No, this is actually Matlab code. You can attach this code to a regular mod-file (you may need to wrap it in a verbatim-block).

Try running
Code: Select all
% Simulate a component model (stochastic trend, deterministic trend, and a
% stationary autoregressive process).
e = .2*randn(200,1);
u = randn(200,1);
stochastic_trend = cumsum(e);
deterministic_trend = .1*transpose(1:200);
x = zeros(200,1);
for i=2:200
x(i) = .75*x(i-1) + e(i);
end
y = x + stochastic_trend + deterministic_trend;
% Instantiates time series objects.
ts0 = dseries(y,'1950Q1');
ts1 = dseries(x,'1950Q1'); % stationary component.
% Apply the Baxter-King filter.
ts2 = ts0.baxter_king_filter();
% Plot the filtered time series.
plot(ts1(ts2.dates).data,'-k'); % Plot of the stationary component.
hold on
plot(ts2.data,'--r'); % Plot of the filtered y.
hold off
axis tight
id = get(gca,'XTick');
set(gca,'XTickLabel',strings(ts0.dates(id)));

as a Matlab m-file

Re: Time Series exercise

PostPosted: Tue Mar 21, 2017 9:02 am
by wjgatt
Thank you, that works!

I had tried running it as a matlab code using F9 first, but it wouldn't run. I now realize it may have partly been because of a typo in the last line, which you corrected in your version.

Code: Select all
strings(ts.dates(id))


should be

Code: Select all
strings(ts0.dates(id))


Thanks again.
Will

Re: Time Series exercise

PostPosted: Tue Mar 21, 2017 9:08 am
by jpfeifer
The thing is that you need the
Code: Select all
dseries
objects in your path. If you did not run Dynare before in your Matlab-session and have only the
Code: Select all
dynare/matlab
-folder in your path, you need to run
Code: Select all
dynare_config

before you can use
Code: Select all
dseries

Re: Time Series exercise

PostPosted: Mon Mar 27, 2017 11:07 am
by wjgatt
Thank you