# Simulate a model using smoothed shocks

**URL:** https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008
**Category:** Dynare help (legacy posts)
**Created:** [11 March 2013 13:35 UTC](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008 "2013-03-11T13:35:09Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Lara](https://forum.dynare.org/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Lara](https://forum.dynare.org/u/Lara)
#### Post date: [11 March 2013 13:35 UTC](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/1 "2013-03-11T13:35:09Z")

</div>

Dear Dynare experts,

I really cannot solve a problem: I would like to simulate a model using the series of exogenous shocks obtained from Bayesian estimation.  
How to do it?

In which part of the dynare code should I write the mat file of the smoothed shocks? Should it be in the shocks block? If so, how exactly?  
Should it be in the stoch\_simul command? If so, how?  
Should I write additional lines in the dynare code?

Would it be possible for you to add an example in order to solve this issue?  
Other users had the same problem, but answers are not satisfactory. In particular;

1. I tried with the example posted by Michel Juillard (example5.mod) on Aug 10,2006 but it does not work ([Static Simulation](https://forum.dynare.org/t/static-simulation/154/1)). I get the following error message .?? Undefined function or variable 'dr\_'  
2)Since the command “shocks(shocks\_file=filename)” does not work ([Shocks\_file not working](https://forum.dynare.org/t/shocks-file-not-working/2900/1)) I tried with “shocks(initval\_file=filename)” but it does not work either. I get the following error message: syntax error, unexpected ‘(’, expecting ‘;’. The filename is a .mat file which contains the smoothed series of the shocks.

Your help is greatly appreciated.

Thanks,  
Lara

---

<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: [11 March 2013 15:11 UTC](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/2 "2013-03-11T15:11:29Z")

</div>

What exactly do you want to do? The posts you cite refer to determinstic simulations under perfect foresight. Your problem, as you are referring to stoch\_simul, sounds like you want to do a stochastic simulation. In that case, the best way is to use the simult\_ function. The code would run along the following lines:

```auto
ex_=[oo_.SmoothedShocks.Median.e_a oo_.SmoothedShocks.Median.e_m]
y0=oo_.dr.ys;
dr=oo_.dr
iorder=1;
y_=simult_(y0,dr,ex_,iorder)
```

where y\_ now contains the simulated values (including the steady state). The shock order required in ex\_ should be the one found in M\_.exo\_names.

---

<div class="post-metadata">

### Author: ![Lara](https://forum.dynare.org/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Lara](https://forum.dynare.org/u/Lara)
#### Post date: [11 March 2013 16:30 UTC](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/3 "2013-03-11T16:30:18Z")

</div>

Dear jpfeifer,  
thanks for your prompt reply. You are right, I want to do a stochastic simulation. Hence I added the lines of code you suggested me and it works!  
I guess that the first value in y\_ is the steady state and the rest are the simulated variables.

Let me just explain the exercise I do. First I estimate a model and I get the series of the smoothed shocks (let me call this dynare code “dyn1.mod”). I save oo\_dr and oo\_.SmoothedShocks as results.mat. Then I simulate a model where I change the value of some parameters (compared to the estimated ones) and use the shocks I have estimated (let me call this dynare code “dyn2.mod”). So in dyn2.mod just before the simult\_ command I write load results (and indeed the series of the shocks are the same as in dyn1.mod).

Thanks,  
Lara

---

<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: [11 March 2013 16:49 UTC](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/4 "2013-03-11T16:49:19Z")

</div>

Just be careful that loading stuff does not overwrite results from the run with changed parameters. From what you write, you should only save and load the oo\_.SmoothedShocks and nothing else. E.g. use

`ex_=[oo_.SmoothedShocks.Median.e_a oo_.SmoothedShocks.Median.e_m];
save results ex_;
`  
in the first mod-file and

```auto
load results ex_;
```

in the second.  
The reason is that both the steady state oo\_.dr.ys and the decision rules oo\_.dr should be from the recent run of Dynare with the changed parameters.

---

<div class="post-metadata">

### Author: ![Lara](https://forum.dynare.org/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Lara](https://forum.dynare.org/u/Lara)
#### Post date: [11 March 2013 17:48 UTC](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/5 "2013-03-11T17:48:25Z")

</div>

Thanks a lot!

Lara

---

<div class="post-metadata">

### Author: ![theta23](https://forum.dynare.org/letter_avatar_proxy/v4/letter/t/c77e96/32.png) [@theta23](https://forum.dynare.org/u/theta23)
#### Post date: [30 May 2015 11:59 UTC](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/6 "2015-05-30T11:59:57Z")

</div>

I’m also interested in model Simulation using estimated shocks. So if I perform Bayesian estimation, then I manually change parameter values to the values I got from estimation (also persistence and standard deviations of shocks) does not it mean that I simulate the model with estimated parameters?  
Or should I explicitly load smoothed shocks series into the code?

Best,  
Theta

---

<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: [31 May 2015 11:14 UTC](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/7 "2015-05-31T11:14:38Z")

</div>

Those are different things: parameters and shocks. If you are interested in a historical counterfactual, you also need the shock values. If you are only interested in simulating the estimated model with arbitrary shocks, you only need to set the parameters.

---

<div class="post-metadata">

### Author: ![leolee](https://forum.dynare.org/letter_avatar_proxy/v4/letter/l/f07891/32.png) [@leolee](https://forum.dynare.org/u/leolee)
#### Post date: [12 November 2015 23:08 UTC](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/8 "2015-11-12T23:08:03Z")

</div>

Dear Prof. jpfeifer

Does the result from the following code you suggested give the same result as those are in “oo\_.SmoothedVariables” when you do not change any parameters and shocks?

`ex_=[oo_.SmoothedShocks.Median.e_a oo_.SmoothedShocks.Median.e_m]
y0=oo_.dr.ys;
dr=oo_.dr
iorder=1;
y_=simult_(y0,dr,ex_,iorder)`

I recently tried this using Smet and Wouters (2007), dynare code from the link below, I found there are some (small and very smoothly curved) gaps between the two results, couldn’t find why.  
[sites.google.com/a/nyu.edu/jerome-williams/smets-and-wouters-aer-2007](https://sites.google.com/a/nyu.edu/jerome-williams/smets-and-wouters-aer-2007)

`y0=oo_.dr.ys;
dr=oo_.dr;
iorder=1;
ex_=[oo_.SmoothedShocks.eta_a oo_.SmoothedShocks.eta_b oo_.SmoothedShocks.eta_g oo_.SmoothedShocks.eta_i oo_.SmoothedShocks.eta_r oo_.SmoothedShocks.eta_p oo_.SmoothedShocks.eta_w];
y_=simult_(y0,dr,ex_,iorder);`
