Plotting IRFs from different models in the same figure

Hi, all.

I got the IRFs after running the dynare for two different models but I would like to compare the impulse responses of the same variable under the same shock from two different model in the same figure . Not simply putting the IRFs together.

If anyone have done this before, please help me. Many thanks.

You can save the impulse response functions (IRFs) as a matlab file. For example, add the following commands after the command stoch_simul:

matrixname = oo_.irfs
save filename.m matrixname

Then, IRFs are accessible in the following way: IRF of variable x to shock e:
Check also dynare manual, page 32.

You can then use “plot commands” to plot what you want.

hope that helps!


See also [Q: combining IRFs into subplotted figures & iterating?)

Could you please give a simple example to explain more about these codes?
For example, my file name is DSGE.mod, and I got a Impulse repsonse matrix, how to save it and then plot it with other impulse response matrixs that could be compared with?
Thank you.

is an example.

Hello DynareUser1 :slightly_smiling_face:
for example, type
dynare DSGE.mod noclearall

You will notice there are a lot of data generated in your MATLAB workspace, especially one document called oo_.

Then input:
DSGEresults = oo_;
save DSGEresults;
These two commands prevent you from losing your data. Sometimes you may run extra documents, like DSGE2.m, DSGE2.mod, DSGE3.m, DSGE3.mod, etc. If at the beginning of these codes you have clear all; close all; then previous outputs oo_ will be deleted, but DSGEresults still maintain.

DSGEresults2 = oo_;
save DSGEresults2;
DSGEresults3 = oo_;
save DSGEresults3;

Now let’s plot figures :grinning:
In a new m-file, without loss of generality, name it as figure_irf.m

clear all;
close all;
load DSGEresults.mat;
load DSGEresults2.mat;
load DSGEresutls3.mat;
plot(DSGEresults.irfs.Consumption_zA * 100, ':', 'Linewidth', 1, 'Color', [0,0.5,1]);
hold all
plot(DSGEresults2.irfs.Consumption_zA * 100, '--', 'LineWidth',1, 'Color', [0.5,1,0]); 
hold all
plot(DSGEresults3.irfs.Consumption_zA*100, '-', 'LineWidth',1, 'Color', [1,0,0.5]); 
title('Consumption','FontName','Times New Roman');

plot(DSGEresults.irfs.Consumption_zA * 100, ':', 'Linewidth', 1, 'Color', [0,0.5,1]);
hold all
plot(DSGEresults.irfs.Consumption_zG * 100, '--', 'LineWidth',1, 'Color', [0.5,1,0]); 
hold all
plot(DSGEresults.irfs.Consumption_zYf *100, '-', 'LineWidth',1, 'Color', [1,0,0.5]); 
title('Consumption','FontName','Times New Roman');

The first subplot is for productivity shock zA in all 3 cases; the second subplot is for shocks zA, zG, and zYf in the first case DSGE.

There are indeed many alternative ways to plot IRFs. You can collect them from Dynare forum, or from authors’ or journals’ websites.

Cheers! :beer: :beer: :beer:


Thank you! Professor jpfeifer. :+1:

Thank you for the reply.Very clear and useful, just suitable for my needs,I really appreciate it.
Cheers! :beers:

1 Like

I used these lines of code to do the same as DynareUser1. However I noticed that the IRFs start from x=1 and not x=0. If I modify the plot() settings I get IRFs that are spike shaped. I don’t understand how to motivate the fact that the IRFs start at x=1 and not x=0.

  1. It’s just a convention to say shocks hit at period 0. They could hit at period 1 or 2 or 100.
  2. Changing the x-axis labeling cannot alter the IRFs. If it did so, you must have made a mistake.

I switched from

plot(money_only_results.irfs.Y_rho_u*100, ‘-.’, ‘Linewidth’, 1, ‘Color’, [1,0,0]); (as sspecified here)


plot([0:options_.irf], [0 money_only_results.irfs.Y_rho_u]*100, ‘-.’, ‘LineWidth’, 1, ‘Color’, [1,0,0]);

The shape of the IRF doesn’t actually change, I just get a straight line from 0 to 1 in the second case, but the shape after that is the same in both cases.

That’s because you are adding a 0 at the beginning. It should be

plot(0:options_.irf-1, money_only_results.irfs.Y_rho_u*100, '-.', 'LineWidth', 1, 'Color', [1,0,0]);

Now it displays the IRFs correctly, thank you so much Professor!