Historical counterfactual analysis

Hi everyone!

I am running a historical counterfactual analysis of Gerali et al. (2010).
I followed a previous example in saving the shocks and variables in a mat file.

load (‘original_modified_results’)

ex_=[oo_.SmoothedShocks.Median.e_A_e oo_.SmoothedShocks.Median.e_eps_K_b oo_.SmoothedShocks.Median.e_j oo_.SmoothedShocks.Median.e_l oo_.SmoothedShocks.Median.e_me oo_.SmoothedShocks.Median.e_mi oo_.SmoothedShocks.Median.e_mk_be oo_.SmoothedShocks.Median.e_mk_d oo_.SmoothedShocks.Median.e_r_ib oo_.SmoothedShocks.Median.e_qk oo_.SmoothedShocks.Median.e_y oo_.SmoothedShocks.Median.e_z ] ;
save results ex_;

vrbls_=[oo_.SmoothedVariables.Median.C oo_.SmoothedVariables.Median.Y oo_.SmoothedVariables.Median.D oo_.SmoothedVariables.Median.B oo_.SmoothedVariables.Median.w_p oo_.SmoothedVariables.Median.J_B oo_.SmoothedVariables.Median.q_h oo_.SmoothedVariables.Median.K oo_.SmoothedVariables.Median.PIW oo_.SmoothedVariables.Median.r_k oo_.SmoothedVariables.Median.ee_z oo_.SmoothedVariables.Median.A_e oo_.SmoothedVariables.Median.ee_j oo_.SmoothedVariables.Median.mk_d oo_.SmoothedVariables.Median.mk_be oo_.SmoothedVariables.Median.mk_bh oo_.SmoothedVariables.Median.ee_qk oo_.SmoothedVariables.Median.m_i oo_.SmoothedVariables.Median.eps_y oo_.SmoothedVariables.Median.eps_l oo_.SmoothedVariables.Median.eps_K_b ] ;
save results1 vrbls_;

  • and uploaded them in the counterfactual.mod

load results ex_;
load results1 vrbls_;
load(‘my_data’);
T = size(ex_,1);

% Simulate shocks after initial period
shocks = ex_ (2:end,:);

%state variables at initial period
y0=oo_.dr.ys;

% update decision rules
[oo_.dr,info,M_,options_] = resol(0,M_,options_,oo_);

dr = oo_.dr;
iorder = 1;
y_ = simult_(y0,dr,ex_,iorder);

However, I’m running into errors, and also simply following the attached link is also not working.
https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/6

I feel like I’m confusing some things here. Does anybody have a clue what I’m doing wrong?
Thanks in advance!
count1.mod (18.5 KB)

You did not provide the full files required to run. Please have a look at

Hi professor Pfeifer,

firstly, thank you very much for your prompt reply. I followed the example file that you linked.

I’ve tried loading my data, smoothedshocks and smoothedvariables in a mat file, following the previous example: load results ex_
However, the following error message is still popping up:

Reference to non-existent field ‘SmoothedShocks’.
Error in count1.driver (line 1037)
ex_=[ex_ oo_.SmoothedShocks.Mean.(M_.exo_names{shock_iter})];
Error in dynare (line 293)
evalin(‘base’,[fname ‘.driver’]) ;

I can’t figure out why dynare does not recognize smoothedshocks, as I have the results from the estimation in the exact same folder.

Would be grateful for any further clues!
count1.mod (18.7 KB)

Again, you are loading stuff

load results ex_ ;
load results1 vrbls_;
load('deviation_data_net');

you did not provide.

I hope it’s complete now

results.mat (4.3 KB)
results1.mat (7.3 KB)
deviation_data_net.mat (5.5 KB)

Where do you actually run the Kalman smoother to compute the smoothed objects?

Dear prof Pfeifer,

sorry for the late reply, we have been trying some ways to run the counterfactual. we estimated a model before, which is named “estimation”. we extracted the smoothed variables and shocks from this estimation by using

load estimation_results

%%%%%%%%%%%%%%%

vParam = oo_.posterior_mode.parameters;

save(‘post_param.mat’,’-struct’,‘vParam’)

% save posterior std dev

vStd = oo_.posterior_mode.shocks_std;

save(‘post_std.mat’,’-struct’,‘vStd’).

However, uploading a zip file of estimation_results is not possible due to the large size. I hope the attached files are sufficient.
count1-2.mod (18.7 KB)
estimation.mod (20.7 KB)
post_param.mat (1.5 KB)
post_std.mat (821 Bytes)

Those are estimation results you mention. They are not the smoothed objects like oo_.SmoothedShocks