Hello, everyone. These days I try to let two different models’ impulse response to be in one same graph. And I have searched some experience from here. But I still can not successfully run it. Can someone tell me the mistakes of my code? Thanks a lot!
My code is following:
dynare benchmark.mod
% save the variables of interest for plotting the irfs
impulseResponses_benchmark.nu = struct('Y',Y_epsilon_nu,'K',K_epsilon_nu,'I', I_epsilon_nu,'C_s',C_s_epsilon_nu,...
'C_b', C_b_epsilon_nu,'H_b',H_b_epsilon_nu,'Q_h',Q_h_epsilon_nu,'w_b',w_b_epsilon_nu,...
'Bnominal',Bnominal_epsilon_nu,'QKnominal',QKnominal_epsilon_nu,'mf',mf_epsilon_nu,'pphi', pphi_epsilon_nu, ...
'r_k',r_k_epsilon_nu,'r_b', r_b_epsilon_nu,'r',r_epsilon_nu,'R',R_epsilon_nu,...
'Q',Q_epsilon_nu,'w_s',w_s_epsilon_nu,'ppi',ppi_epsilon_nu,'N',N_epsilon_nu);
load('impulseResponses_benchmark.nu');
irf1 = impulseResponses_benchmark.nu;
save irf1;
dyanre model_LTV.mod noclear
impulseResponses__model_LTV.nu = struct('Y',Y_epsilon_nu,'K',K_epsilon_nu,'I', I_epsilon_nu,'C_s',C_s_epsilon_nu,...
'C_b', C_b_epsilon_nu,'H_b',H_b_epsilon_nu,'Q_h',Q_h_epsilon_nu,'w_b',w_b_epsilon_nu,...
'Bnominal',Bnominal_epsilon_nu,'QKnominal',QKnominal_epsilon_nu,'mf',mf_epsilon_nu,'pphi', pphi_epsilon_nu, ...
'r_k',r_k_epsilon_nu,'r_b', r_b_epsilon_nu,'r',r_epsilon_nu,'R',R_epsilon_nu,...
'Q',Q_epsilon_nu,'w_s',w_s_epsilon_nu,'ppi',ppi_epsilon_nu,'N',N_epsilon_nu);
load('impulseResponses_model_LTV.nu');
irf2 = impulseResponses_benchmark.nu;
save irf2;
plot_irfs %it's another file, the context of the file is following:
%%
AllNamefields = fieldnames(impulseResponses);
AllshockNames = AllNamefields(1:1);
AllvariableNames = fieldnames(impulseResponses.nu);
% j for shock types, i for variable
for j = 1:1
figure
for i = 1:20
shockName = AllshockNames{j};
variableName = AllvariableNames{i};
subplotName = ['subplot' num2str(i)];
subplotName = subplot(5,4,i);
subplot(5,4,i)
plot(impulseResponses_benchmark.(shockName).(variableName),'b','LineWidth',1.5)
line(xlim(), [0,0], 'LineWidth', 1, 'Color', 'k');
hold on
plot(impulseResponse_model_LTV, 'k--', 'LineWidth',1.5);
title((variableName))
set(subplotName,'FontSize',13,'XGrid','on','YGrid','on','box','off');
end
end