Counterfactual analysis in Dynare with shocks shut to 0 for a time period

Dear all,

I am trying to run a counterfactual analysis in dynare. I use a log-linear calibrated model with the following data: output (y_obs), inflation (pi_c_obs), exports (ex_obs) and imports (im_obs). Their theoretical counterparts are: y_h, pi_c_h, ex_h and im_h. The model has two shocks: eps_d (terms of trade shocks) and eps_y (foreign output shocks).

I would like to compare the results between the actual scenario, where the terms of trade shocks (eps_d) are positive from period 0 to 142, then are set to 0 from time period 143 to 181 and then are positive again, and the counterfactual scenario where the terms of trade are positive from 0 to 142 and then set to 0 from period 143 to the last period (240). Is there a way to do that in dynare or should I use matlab to perform the analysis between the factual and counterfactual scenarios ? I checked in the forum but the questions and solutions aren’t similar to mine.

Hope you can help me !

Thanks !

Usually, this can be done using the simult_-function. See

Dear Prof. Pfeifer,

I tried to follow the steps from: https://github.com/DynareTeam/dynare/blob/4.5/tests/kalman_filter_smoother/compare_results_simulation/fs2000_ML.mod
but my simulations are not even close to the data. They look very weird. I don’t know what I am doing wrong… Can you please help me ?
Model.mod (13.7 KB) makeDta.m (50 Bytes) makeDta.xlsx (78.6 KB)

Your plotting is wrong. You are not plotting the data, but rather the simulation of stoch_simul(periods=240). It should e.g. by

figure();
plot(num(:,1))
hold on;
plot(y_(strmatch('y_obs',M_.endo_names,'exact'),:),'r--');
hold on

You’re right thank you very much !! The thing is that now y_obs and pi_c_obs completely match but im_obs and ex_obs don’t match with the simulated data at all. I checked the output in SmoothedVariables and I can see that Smoothed.Variables.y_obs and Smoothed.Variables.pi_c_obs perfectly match the data but Smoothed.Variables.ex_obs and Smoothed.Variables.im_obs dont. I don’t understand why they dont.
Model.mod (13.8 KB) makeDta.m (50 Bytes) makeDta.xlsx (78.6 KB)

The reason is that your model is stochastically singular. You observables have an exact linear relationship, making it impossible to exactly fit all of the data simultaneously.

Right !! I see, thank you very much for pointing this. But what should I do then ? I really need to do the analysis on at least 3 observed variables (output, inflation and exports). I know that when I estimate the model I can add measurement errors that I will estimate so that I can have as many shocks as observed variables. But in the case of calibration I am not sure what to do? Should I also use measurement errors where I fix the value of the shock?

You could add calibrated measurement error. But that does not change the fact that your model is fundamentally inconsistent with the observed data, i.e. misspecified.

Now I am confused… what should I do then ?

I added a calibrated measurement error for exports and slightly changed the value of one of my parameters and now it fits. However I tried to perform a counterfactual analysis with the terms of trade shocks (epsd) fixed to 0.0025 from period 181 to the end but I think there must be a problem with my codes since the counterfactual scenario ends up behaving the exact same way for output and inflation. If you have some time to help me find my problem i would really appreciate it. Thanks a lot for your help so far !!

Model.mod (16.2 KB) makeDta.xlsx (78.6 KB) makeDta.m (50 Bytes)

I don’t see what you mean. After period 180, all series are different in the counterfactual than in the data.

Sorry I wasn’t clear. Output growth and inflation have the exact same counterfactual, which makes no sense. The counterfactual scenarios are different from the data for each variables but what is weird is that output growth and inflation end up having the exact same shape and values for the counterfactual data (need to compare the counterfactual shapes and values for output growth and inflation). This makes me wonder that there must be something wrong with my codes.