Q: combining IRFs into subplotted figures & iterating?

Thank you so much for your help but unfortunately this has not worked… It executes perfectly the responses for the 3 models and all of them share same variables and shocks. I get this error:

Reference to non-existent field ‘y_eps_e’.

Error in combifixednew (line 27)
eval([‘irf2.’ var{1,jj},ending_cell{1,ii}]);

Error in run (line 91)
evalin(‘caller’, strcat(script, ‘;’));

Please provide the fixednewconresults.mat

Dear Prof. Pfeifer,

I applied your solution to my model and it works!
But my plot looks not that nice. I do not like the axis and I want to have a legend for the shock parameter as in the other plot.

dynare

My plot with the matlab code looks much better, but for that I coded everything:discretion

subplot(2,2,4); hold on;
plot(t, w_solution(1,t+1),lineStyle{n},‘Linewidth’,0.5)
xlabel(‘t’); ylabel(‘nu’); title(‘Shock’)
legend(’\rho = 0’,’\rho = 0.8’)
box on

if you compare both plots the second one looks much better. How can I change the first plot to look as the second?

I am not sure I understand. Did you generate both plots. If yes, you should be able to tell the difference in plot commands and options.

Dear Prof. Pfeifer,
Yes, I generated both plots.
The first plot is the one of my Dynare Code and the second one of my Matlab code for the same model .

The first plot I coded as followed:

figure
for jj=1:length(var)
subplot(1,2,jj)
eval(‘irf1.’ var{1,jj},ending_cell{1,ii}]);
eval(‘irf2.’ var{1,jj},ending_cell{1,ii}]);
hold on
plot(HOR,[eval([‘irf1.’ var{1,jj},ending_cell{1,ii}])],‘LineWidth’,1,’-k’,HOR,[eval([‘irf2.’ var{1,jj},ending_cell{1,ii}])],‘LineWidth’,1,’–r’)
title([var{1,jj}] )
end

I generated the second plot with the follwing code

lineStyle = {‘k->’, ‘k-o’};
subplot(2,2,1); hold on;
plot(t, x_solution(t+2), lineStyle{n}, ‘LineWidth’,0.5)
xlabel(’ t ‘); ylabel (’ x ‘); title(’ output gap ‘)
set(gca,‘XTickLabel’,{‘0’,‘5’,‘10’,‘15’,‘20’})
box on
subplot(2,2,2); hold on;
plot(t, w_solution(2,t+2),lineStyle{n}, ‘LineWidth’,0.5)
xlabel(’ t ‘); ylabel(’ \pi ‘); title(‘inflation’)
set(gca,‘XTickLabel’,{‘0’,‘5’,‘10’,‘15’,‘20’})
box on
subplot(2,2,3); hold on;
plot(t, i_solution(t+2),lineStyle{n},‘Linewidth’,0.5)
xlabel(‘t’); ylabel(‘i’); title(‘nominal interest rate’)
set(gca,‘XTickLabel’,{‘0’,‘5’,‘10’,‘15’,‘20’})
box on
subplot(2,2,4); hold on;
plot(t, w_solution(1,t+1),lineStyle{n},‘Linewidth’,0.5)
xlabel(‘t’); ylabel(‘nu’); title(‘Shock process’)
set(gca,‘XTickLabel’,{‘0’,‘5’,‘10’,‘15’,‘20’})
legend(’\rho = 0’,’\rho = 0.8’)
box on

If you compare both the second plot looks much better. I do not like the first plot not to start from the axis. I want to have this legend as in the subplot shock process. And the second plot is in a square. Now I want to find a way to generate the first exactyl as the second plot.

Can I include this part for e.g

" xlabel(’ t ‘); ylabel(’ \pi '); title(‘inflation’)

in my dynare code? or how can I improve the look of the first plot?

Both are Matlab codes. There are not Dynare commands for plotting. You can simply modify the first graph by using the same Matlab commands as for the second one.

Thinks, this code is used into my figure, very useful, it help me save much time for plot.

Thanks it works now!!

Dear All,

Is it possible to use that code if we want to have negative or positive shocks ?
For example If we want to have negative productivity shock. As in dynare we can do it by usin -oo_.irfs simply adding negative in front. Is that also possible here ?

Thank you

Sure. Add a minus before the irf1 in the eval-statement

Professor Pfeifer,

Thank you

Best

Hello,

I combined 4 IRFs in 4 subplots and it works with taylor rule (stoch_simul) and ramsey_policy but not with discretionary_policy (although I only changed the filenames in the code below and they all work on their own after editing discretionary_policy_1.m). Is this due to this bug or some failure by me?

Thank you in advance
ompD.mod (754 Bytes) ompDirfs.m (1.1 KB)
(ompD1/2/3 are just line 25 with “epsu(-1/-2/-3)”)

From what I can see, it’s indeed this bug. Did you try the unstable version?

I just tried the latest unstable version. The fix for above is implemented now but multiple IRF with discretionary_policy doesn’t work unfortunately.

What is the error message you are getting?

Like in the fixed single IRF case starting with an error msg of different dimensions (causing the others?).
This happens after the 2nd preprocessing (completed) / first figure:
"Unable to perform assignment because the size of the left side is 6-by-6 and the size of the right side is 5-by-5.

Error in discretionary_policy_engine (line 101)
H0(1:endo_nbr,1:endo_nbr)=H00;

Error in discretionary_policy_1 (line 106)
[H,G,info]=discretionary_policy_engine(A.lag,A.contemp,A.lead,B,W,M_.instr_id,beta,options_.dp.maxit,options_.discretionary_tol,options_.qz_criterium,Hold);

Error in stoch_simul (line 85)
[~,info,M_,options_,oo_] = discretionary_policy_1(options_.instruments,M_,options_,oo_);

Error in discretionary_policy (line 37)
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list);

Error in ompD1.driver (line 220)
[info, oo_, options_, M_] = discretionary_policy(M_, options_, oo_, var_list_);

Error in dynare (line 289)
evalin(‘base’,[fname ‘.driver’]) ;

Error in ompDirfs (line 7)
dynare ompD1.mod noclearall"

Discretionary policy employs persistent variables. You must not invoke the noclearall option.

Thanks alot Prof. Pfeifer!

You are working with perfect foresight. In that case, there is no oo_.irfs. You need to adjust your code to access the respective entries of oo_.endo_simul

Thank you for your reply. I have tried doing that in combinedmodel.m (690 Bytes) but still get the same error:

Error using eval
Unrecognized function or variable ‘mat1y_N_gap_epsA_N’.

Error in combinemodel (line 20)

  •   eval(['mat1' var{1,jj},ending_cell{1,ii}]);*
    

I would really appreciate your help with this.