Q: combining IRFs into subplotted figures & iterating?

Without the files to replicate the problem, it is impossible to answer.

Thanks you for responding. Those are the files :
ssfriction_amenage.mod (10.5 KB)
ssfriction_fixe.mod (10.5 KB)

Have not had time to run the code… but did you try

plot(HOR, irf1,..other plot options); hold on;
plot(HOR, irf2...other plot options)

Currently, you are trying to plot HOR on the x axis with 2 variables on the yaxis,using a single plot command…that could explain the error. your syntax seems to be similar to the old plotyy command
https://www.mathworks.com/help/matlab/ref/plotyy.html

Another simple way to do it, would be

plot([irf1 irf2])

if they are of the same lengths…
Reuben

1 Like

The last part should be


for ii=1:length(ending_cell)
    HOR=1:options_.irf;
    var={'lab','inv'};
    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}]);
        load irf1
        load irf2
        hold on
        plot(HOR,[eval(['irf1.' var{1,jj},ending_cell{1,ii}])],'-k',HOR,[eval(['irf2.' var{1,jj},ending_cell{1,ii}])],'--r','LineWidth',2)
        title([var{1,jj}] )
    end
end
1 Like

looks like plot(x1,y1,x1,y2) works fine. just checked it.

1 Like

Thank you so much. My model is working now.

Hi,
I am trying to combine IRFs of two models in one graph, but I am getting this error Undefined function or variable ‘epsilon_phi_X1’.
figure;
irf_epsilon_phi=[epsilon_phi_X1 epsilon_phi_X2];
subplot(3,3,1);
h=plot(irf_epsilon_phi);
set(h(1),‘color’,‘k’);
set(h(2),‘Marker’,’*’,‘color’,‘k’);
set(h(3),‘Marker’,‘o’,‘color’,‘k’);
axis tight;
title(‘epsilon_phi’)

You need to provide the codes.

Hello,
I solve the model with perfect foresight simulation, so I don’t have oo_.irfs in my results. When I plot the the simulated path of each model, I directly use the name of the variables (ex: plot(eval([‘100*(’ vari{1} ‘(X))’]) where vari is a vestor of the names of my variables). Now, in order to combine the plots of two models, I’m struggling to find where the endogenous variables are stored, so that I can call them and save them as it is done here for IRF1 and IRF2. I can see them in the workspace, but I don’t know how to get access to them.
Thank you for your help!

All perfect foresight results are stored in oo_.endo_simul

Hi there: I was wondering whether I could get some help in fixing this little error: I don´t get the plots because they do not have the same lenght. I though Matlab would adjust this. The impulse responses are both for same variables. Here is my code:

ERROR

Many thanks

I would need to see the codes/files to replicate the issue.

Thank you for your help. Please, find attached both files and the m.file for the combined impulse responses. For know I would just like to combine responses for eps_k
combi1.m (842 Bytes)
departshock1.mod (3.1 KB)
macroproject.mod (3.4 KB)

It should be

dynare macroproject.mod;
irf1 = oo_.irfs;
save macroprojectresponses.mat irf1;

dynare departshock1.mod;
irf2 = oo_.irfs;
save departshock1results.mat irf2;
load('macroprojectresponses.mat','irf1');
load('departshock1results.mat','irf2');

ending_cell={'_eps_k'};
%'y', 'dp', 'cs', 'cb', 'h', 'hs', 'r', 'qh', 'qz'
for ii=1:length(ending_cell)
    HOR=1:options_.irf;
    var={'y', 'dp', 'cs', 'cb'};
    figure
    for jj=1:length(var)
        subplot(2,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}])],'-k',HOR,[eval(['irf2.' var{1,jj},ending_cell{1,ii}])],'--r','LineWidth',2) ;
        title([var{1,jj}] )
    end
end
1 Like

Hello!

That was very helpful. Many thanks for that. Is there any way I can use the same code and combine 3 or 4 models instead of 2 only? I tried it by saving as well the responses and loading them firstly and then I included HOR,[eval(['irf3.' var{1,jj},ending_cell{1,ii}])], --j' after '--r' but I could not make it work.

Thank you so much.

What is the error message?

Here is the code I use to combine the three models:

dynare fixednew.mod;
irf1 = oo_.irfs;
save fixednewresponses.mat irf1;

dynare fixednewcon.mod;
irf2 = oo_.irfs;
save fixednewconresults.mat irf2;

dynare fixednewcon2.mod;
irf3 = oo_.irfs;
save fixednewcon2results.mat irf3;
load('fixednewresponses.mat','irf1');
load('fixednewconresults.mat','irf2');
load('fixednewcon2results.mat','irf3');



ending_cell={'_eps_e'};
% 'y', 'bt','ct', 'cu', 'hc', 'hz','hu', 'dp', 'q', 'qz', 'r', 'l', 'dy'
for ii=1:length(ending_cell)
    HOR=1:options_.irf;
    var={ 'y', 'bt','ct', 'cu'};
    figure
    for jj=1:length(var)
        subplot(2,2,jj)
        eval(['irf1.' var{1,jj},ending_cell{1,ii}]);
        eval(['irf2.' var{1,jj},ending_cell{1,ii}]);
        eval(['irf3.' var{1,jj},ending_cell{1,ii}]);
        hold on
        plot(HOR,[eval(['irf1.' var{1,jj},ending_cell{1,ii}])],'-k',HOR,[eval(['irf2.' var{1,jj},ending_cell{1,ii}])],'--r', HOR,[eval(['irf3.' var{1,jj},ending_cell{1,ii}])], '---j' ,'LineWidth',1) ;
        title([var{1,jj}] )
    end
end



And this is the error I obtain: 

**Error using plot**
**Error in color/linetype argument.**

**Error in combifixednew (line 30)**
**        plot(HOR,[eval(['irf1.' var{1,jj},ending_cell{1,ii}])],'-k',HOR,[eval(['irf2.' var{1,jj},ending_cell{1,ii}])],'--r',**
**        HOR,[eval(['irf3.' var{1,jj},ending_cell{1,ii}])], '---j' ,'LineWidth',1) ;**

In Matlab there is no linetype ---. Try :m instead of ---j

line types work for me for merging 2 models into the same plot. I used the code you corrected for me a few weeks below. (please see above). I basically took the code that worked before and added a new “HOR” term.

Thank you for your help. Maybe i need to do it in another way? The only way of plotting responses from dynare that I know is this one

I am saying that

        plot(HOR,[eval(['irf1.' var{1,jj},ending_cell{1,ii}])],'-k',HOR,[eval(['irf2.' var{1,jj},ending_cell{1,ii}])],'--r', HOR,[eval(['irf3.' var{1,jj},ending_cell{1,ii}])], '---j' ,'LineWidth',1) ;

should be

        plot(HOR,[eval(['irf1.' var{1,jj},ending_cell{1,ii}])],'-k',HOR,[eval(['irf2.' var{1,jj},ending_cell{1,ii}])],'--r', HOR,[eval(['irf3.' var{1,jj},ending_cell{1,ii}])], ':m' ,'LineWidth',1) ;