Counterfactual code error


#1

Hi everyone,

As part of my research I must perform a counterfactual analysis between two different simulated economies, however, I am having trouble with the code. The structure of my counterfactual code is as follows:

  1. Benchmark model loading.
  2. Sample size definition.
  3. Initial values definition (previously estimated values of the parameters and standard deviations of structural shocks are taken as initial values).
  4. Alternative model loading.
  5. Alternative model simulation taking into account the initial values.

The error shown is: “Error using load - Number of columns on line 14 of ASCII file Modelo_benchmark.mod must be the same as previous lines”. This makes sense since I am loading a code that defines the economic model and not a database. Given this error I wonder if Im making a concept error in the code or is it just a programmation mistyping. If necessary, I attach the code for the counterfactual analysis and the benchmark model code.

Thank you very much!
Contrafactual.m (3.14 KB)
Modelo_benchmark.mod (8.83 KB)


#2

Why exactly are you trying to load a mod-file, which is a text file. Shouldn’t you be running Dynare on the mod-file and then load the _results.mat-file?


#3

Dear Johannes,

Thank you very much for your answer, it helped me a lot to correct my mistake on the code. Now everything is running fine.


#4

Dear professor jpfeifer ,
I read some DSGE papers with counterfactual analysis(comparing a certain variable y’s path under one specific shock and the real path of y), but I don’t know how they get these results. I have searched a lot,including the 'RBC_news_shock_model.mod you recommended. But I am still very confused about the simult_ function, What’s the exact process if I want to get graphs of counterfactual?
Here I pose Gologan’s countractual.m file for explanation:

T =66;
y0 = [oo_.SmoothedVariables.y(1) + oo_.steady_state(1);
oo_.SmoothedVariables.c(1) + oo_.steady_state(2);
oo_.SmoothedVariables.k(1) + oo_.steady_state(3);
oo_.SmoothedVariables.I(1) + oo_.steady_state(4)];
ex_ = [oo_.SmoothedShocks.eps_c(2:T),oo_.SmoothedShocks.eps_I(2:T)]
dr = oo_.dr;
iorder = 1;
y_= simult_(y0,dr,ex_,iorder);
My question is:
  1. If I don’t change the code, does the result of y_ has the same meaning with oo_.SmoothedVariables I got by estimation command? (since the result of y_ is same with oo_.SmoothedVariables. )
  2. Take y as example,If I just impose one unit eps_c shock to y at t=10 and I do not impose any shocks to y at any other time, where should I change? How about impose one unit eps_c shock at t=10:20?Then, how about impose one unit eps_c at t=10 and impose one unit eps_I at t=20?
  3. Can I interpret the y_ as the counterfactual results, while the real value of variables is the data I used as observable variables? If so,how to apply counterfactual analysis to those variables that can’t be observed?
  4. What does the y_ exactly mean, is the result of under both one unit shocks of eps_c and eps_I at t=2:T?
    Sincerely,
    Kairey

#5

The simult_-function allows you to simulate the model you solved with perturbation techniques from an arbitrary starting point (called y0 above) with arbitrary shocks called ex_.

  1. The code you reference above starts at the steady state and then uses the estimated smoothed states from the Kalman smoother. If you start at the smoothed initial state and use the smoothed shocks, you will get back the observed data series. Note that in recent Dynare version the smoothed variables already include the mean/steady state, so the above code is outdated.
  2. If you want to change the shock sequence, you need to adjust ex_. In https://github.com/JohannesPfeifer/DSGE_mod/blob/master/RBC_news_shock_model/RBC_news_shock_model.mod you can see how to create this shock matrix by spanning it and then selecting individual entries.
  3. The simult_-function will return simulation results for all variables in the model, not just the observed ones. You only need to select the ones you are interest in.
  4. y_ is the simulated series based on the sequence of shocks provided to the simult_-function. In the example above, that is eps_c and eps_I

#6

Dear professor jpfeifer ,
Thanks very much, I will try to think about it.
Best,
Kairey