 # Simulation with real data

Hi all,

After solving the DSGE model by dynare which have a productivity/TFP shock, I want to check if the model can account for the recession in 2008.
The TFP shock is log AR(1): ln(A) = \rho ln(A(-1) + eA

So now I have the position function solved by Dynare, and the data series of TFP.
My plan is to find out the simulated paths from the model for some important variables like output, consumption, investment. Then compare those simulated paths with the paths created from real data 10 years from the recession.

But I am still struggling with how to produce the simulated paths from the model solution and data on the TFP?

Could any one here give me a suggestion?

Thank you!

I am not sure I understand your problem here. Are you trying to simulate the model with the TFP you observe? Is TFP the only shock exogenous variable in the model?

I assume that the TFP shock is the only source of randomness in the model:

\log A_t = \rho \log A_{t-1} + e_{A,t}

If you call the stoch_simul command, Dynare will simulate the model by taking draws for e_{A,t} in a normal distribution. If my understanding of your problem is correct, you want instead to simulate the model with the observed TFP. Here is what I would do:

1. Compute recursively a sequence of innovations e_{A,T} consistent with your measure of TFP (assuming you have an initial condition A_0):
e_{A,t} = \log A_t - \rho \log A_{t-1}\quad \text{ for }t=1,\dots,T
1. You need to call an internal matlab routine called simult_ (available in the matlab subfolder) providing the sequence (in a vector) obtained in the previous step as the third input (ex). You will figure out easily how to call this function by looking how we do it in Dynare (look at stoch_simul.m and simult.m in the same folder).

Best,
Stéphane

1 Like

See

https://github.com/JohannesPfeifer/DSGE_mod/blob/master/RBC_news_shock_model/RBC_news_shock_model.mod

for an example on how to use the simult_-function to simulate a stochastic model with a given sequence of shocks.

2 Likes

Dear Stephane,

1. You need to call an internal matlab routine called simult_ (available in the matlab subfolder) providing the sequence (in a vector) obtained in the previous step as the third input ( ex ).

–> What do you mean by the “matlab subholder”, You mean I need to create it or this is available after running Dynare (i checked after running a mod file and see no matlab subfolder created)

You will figure out easily how to call this function by looking how we do it in Dynare (look at stoch_simul.m and simult.m in the same folder).

–> Again, I could not find stoch_simul.m and simult.m, since I could not find the folder as well.

Sorry if my question is stupid …

Thank you a lot!

I suppose that the example referenced by @jpfeifer solves your problem.

If you installed dynare in C:/dynare/4.5.6 you have a subfolder inside called matlab (and more subfolders inside C:/dynare/4.5.6/matlab where all the matlab routines are located. C:/dynare/4.5.6/matlab is the folder you must add to the matlab path, to get dynare working. In this folder you will find simult_.m, simult.m and stoch_simul.m routines.

Best,
Stéphane.

2 Likes

Thanks @stepan-a

I am still reading the file Johannes sent. I haven’t figure out how it solves my problem, but will try to get it.

I am using dynare 4.5.5 indeed, but still found the .m files based on your instructions.

Have a nice day!

Hi all,

I know that dynare can compute the variance decomposition for the contributions of the shocks.
But now if I am using real data for shocks in simulation, is there a way to compute the variance decomposition as well?

Thanks,

Difficult to think about this since you simulate your model conditionally on a path for the exogenous variables. So unless you have a probabilistic models for these paths, I do not see how to compute a variance (a fortiori a variance decomposition).

Best,
Stéphane.

1 Like

What you are actually trying to do is a historical decomposition. In a linear model, this boils down to simulating the model with one shock at a time and seeing how the counterfactual series looks like. Of course, if your model was not estimated using full information techniques, you have the problem outlined at

namely that the shock contributions do not sum to the observables.

1 Like

Dear Stéphane,

Is there any source that explains how to feed in shocks into the model (2nd step)? It is still not clear after I investigated Johannes’s mod example file for the simult_ -function. Do we need to manually edit the “simult_.m” file?

Thanks,
Ruslan

What exactly are you trying to do? Usually, you only need to adjust the shock_matrix.

I am trying to assign specific values for the shocks in each period that I obtain from real data.

Do you mean that, if I have 9 values (value1, value2, …, value9) for an exogenous ‘shock’ variable in 9 periods, I have to write down:

shock_matrix(1,strmatch(‘shock’,M_.exo_names,‘exact’)) = value1
shock_matrix(2,strmatch(‘shock’,M_.exo_names,‘exact’)) = value2

shock_matrix(9,strmatch(‘shock’,M_.exo_names,‘exact’)) = value9

Thanks,
Ruslan

Here is my updated mod file:

StEx3.mod (3.5 KB)

It reports some errors. I can run the file in 4.6.4 without any error messages.

Thank you, Johannes.

Errors were because of an older version of Dynare that was using.

Now the issue is that my
StEx3.mod (4.3 KB)
does not generate the intended values for the variable ‘F’. In my model ‘F’ must be calculated as: log(F)=log(F(-1))+oil_ch (given in line 56) where “oil_ch” gets values in the ‘shock_matrix’.

Ruslan

Could you please elaborate? And did you take into account the linear approximation?

F is the oil revenue in my model (measured as fraction of output).
oil_ch is obtained as: oil_ch=log(F)-log(F(-1)) using the real data and I am using lines 102-116 to provide the obtained sequence.

However when I simulate, the values of F are far from what is in actual data.

None of my equations are log linerized. I assume Dynare does it automatically. Maybe my mistake is in this.

RA

Your shocks are huge. The first one is 360 percent. Obviously a first order approximation will be poor.

I see. Appreciate if you could tell me what can I do in this situation.

RA

Check whether the scaling is correct. Did you multiply everything by 100 or is there really a 360 percent shock?