# Time Series exercise

**URL:** <https://forum.dynare.org/t/time-series-exercise/6090>\
**Category:** dseries/data/reporting\
**Created:** [21 March 2017 08:22 UTC](https://forum.dynare.org/t/time-series-exercise/6090 "2017-03-21T08:22:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wjgatt](https://forum.dynare.org/letter_avatar_proxy/v4/letter/w/82dd89/32.png) [@wjgatt](https://forum.dynare.org/u/wjgatt)\
**Post date:** [21 March 2017 08:22 UTC](https://forum.dynare.org/t/time-series-exercise/6090/1 "2017-03-21T08:22:48Z")

</div>

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:

```auto
ERROR: ts_model.mod: line 21, col 1 - line 28, col 0: syntax error, unexpected $end
```

Could anyone clarify this please?

Thanks  
Will

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [21 March 2017 08:44 UTC](https://forum.dynare.org/t/time-series-exercise/6090/2 "2017-03-21T08:44:37Z")

</div>

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

`% 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

---

<div class="post-metadata">

**Author:** ![wjgatt](https://forum.dynare.org/letter_avatar_proxy/v4/letter/w/82dd89/32.png) [@wjgatt](https://forum.dynare.org/u/wjgatt)\
**Post date:** [21 March 2017 09:02 UTC](https://forum.dynare.org/t/time-series-exercise/6090/3 "2017-03-21T09:02:59Z")

</div>

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.

```auto
strings(ts.dates(id))
```

should be

```auto
strings(ts0.dates(id))
```

Thanks again.  
Will

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [21 March 2017 09:08 UTC](https://forum.dynare.org/t/time-series-exercise/6090/4 "2017-03-21T09:08:49Z")

</div>

The thing is that you need the `dseries` objects in your path. If you did not run Dynare before in your Matlab-session and have only the `dynare/matlab`-folder in your path, you need to run

```auto

```

before you can use `dseries`

---

<div class="post-metadata">

**Author:** ![wjgatt](https://forum.dynare.org/letter_avatar_proxy/v4/letter/w/82dd89/32.png) [@wjgatt](https://forum.dynare.org/u/wjgatt)\
**Post date:** [27 March 2017 11:07 UTC](https://forum.dynare.org/t/time-series-exercise/6090/5 "2017-03-27T11:07:11Z")

</div>

Thank you
