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:

Benchmark model loading.

Sample size definition.

Initial values definition (previously estimated values of the parameters and standard deviations of structural shocks are taken as initial values).

Alternative model loading.

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.

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?

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:

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

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?

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?

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

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

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.

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.

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