Simulate a model using smoothed shocks

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). 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) 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.


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:

ex_=[oo_.SmoothedShocks.Median.e_a oo_.SmoothedShocks.Median.e_m]

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.

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).


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

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.

Thanks a lot!


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?


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.

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.

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);