%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This File shall help to merge impulse response functions created from
% DSGE models with the Dynare package. If there is a better way to do this,
% please point it out to me. For any questions and recommendations, write a
% mail to p.wegmueller@students.unibe.ch
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% First, load the xy_results.mat that you wish to extract the IRFs from.

load model1_results.mat
irf1=oo_.irfs;
keep irf1

load model2_results.mat %model 1a
irf2=oo_.irfs;
keep irf1 irf2

load modelxy_results.mat
irf3=oo_.irfs;
keep irf1 irf2 irfxy              % number all the irf graphs that you need

% Define variables and colors to be loaded as strings 

var=strvcat('y_e', 'c_e', 'h_e', 'k_e', 'd_e', 'i_e', 'tb_e', 'ca_e', 'a_e');
color=strvcat('b','g','r','c','m');

save irf

load irf

% the loop will load the IRFs in a subplot to be specified as desired

for i=1:3
    subplot(3,3,i)
    for j=1:5               %Load the Irf's from p.ex. 1 to 5
%        if j==4            %If you want to exclude a variable of a
                            %specific model to be plottet, name it here.          
%        else
            [eval(['irf' num2str(j) '.' var(i,:)])];
            hold on
            plot(0:9,[eval(['irf' num2str(j) '.' var(i,:)])],color(j),'LineWidth',1)
            title(['Response of ' var(i,:)] )
    end
    
end

legend({'model1','model1a','model2','model3', 'model4'}, 'Location', 'EastOutside')