Time Series exercise

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Time Series exercise

Postby wjgatt » Tue Mar 21, 2017 8:22 am

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
wjgatt
 
Posts: 23
Joined: Thu Jun 16, 2011 7:23 pm

Re: Time Series exercise

Postby jpfeifer » Tue Mar 21, 2017 8:44 am

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
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Time Series exercise

Postby wjgatt » Tue Mar 21, 2017 9:02 am

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
wjgatt
 
Posts: 23
Joined: Thu Jun 16, 2011 7:23 pm

Re: Time Series exercise

Postby jpfeifer » Tue Mar 21, 2017 9:08 am

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
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Time Series exercise

Postby wjgatt » Mon Mar 27, 2017 11:07 am

Thank you
wjgatt
 
Posts: 23
Joined: Thu Jun 16, 2011 7:23 pm


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 6 guests