# Q: combining IRFs into subplotted figures & iterating?

**URL:** <https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609>\
**Category:** Stochastic simulations\
**Created:** [8 January 2014 13:21 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609 "2014-01-08T13:21:14Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [8 January 2019 16:59 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/21 "2019-01-08T16:59:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![simsima](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@simsima](https://forum.dynare.org/u/simsima)\
**Post date:** [8 January 2019 17:51 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/22 "2019-01-08T17:51:42Z")

</div>

Thanks you for responding. Those are the files :  
[ssfriction\_amenage.mod](https://forum.dynare.org/uploads/default/original/2X/6/6630d58720a7515fc1ccb6af9ec6c7946d4867fc.mod) (10.5 KB)  
[ssfriction\_fixe.mod](https://forum.dynare.org/uploads/default/original/2X/c/c13c54928db68c26fb7a449e39d45b25a3df5d52.mod) (10.5 KB)

---

<div class="post-metadata">

**Author:** ![punnoosejacob](https://forum.dynare.org/user_avatar/forum.dynare.org/punnoosejacob/32/5976_2.png) [@punnoosejacob](https://forum.dynare.org/u/punnoosejacob)\
**Post date:** [8 January 2019 19:26 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/23 "2019-01-08T19:26:34Z")

</div>

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

```auto
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](https://www.mathworks.com/help/matlab/ref/plotyy.html)

Another simple way to do it, would be

```auto
plot([irf1 irf2])
```

if they are of the same lengths…  
Reuben

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [8 January 2019 19:54 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/24 "2019-01-08T19:54:03Z")

</div>

The last part should be

```auto

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

```

---

<div class="post-metadata">

**Author:** ![punnoosejacob](https://forum.dynare.org/user_avatar/forum.dynare.org/punnoosejacob/32/5976_2.png) [@punnoosejacob](https://forum.dynare.org/u/punnoosejacob)\
**Post date:** [9 January 2019 18:02 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/25 "2019-01-09T18:02:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![simsima](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@simsima](https://forum.dynare.org/u/simsima)\
**Post date:** [9 January 2019 18:31 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/26 "2019-01-09T18:31:47Z")

</div>

Thank you so much. My model is working now.

---

<div class="post-metadata">

**Author:** ![bonifaceyemba](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@bonifaceyemba](https://forum.dynare.org/u/bonifaceyemba)\
**Post date:** [1 February 2019 16:32 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/27 "2019-02-01T16:32:15Z")

</div>

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’)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [2 February 2019 08:57 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/28 "2019-02-02T08:57:57Z")

</div>

You need to provide the codes.

---

<div class="post-metadata">

**Author:** ![dben](https://forum.dynare.org/letter_avatar_proxy/v4/letter/d/e99b99/32.png) [@dben](https://forum.dynare.org/u/dben)\
**Post date:** [6 May 2019 07:00 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/29 "2019-05-06T07:00:51Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [8 May 2019 08:49 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/30 "2019-05-08T08:49:59Z")

</div>

All perfect foresight results are stored in `oo_.endo_simul`

---

<div class="post-metadata">

**Author:** ![AITANAgf](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@AITANAgf](https://forum.dynare.org/u/AITANAgf)\
**Post date:** [27 May 2019 16:33 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/31 "2019-05-27T16:33:32Z")

</div>

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:

 ![image](https://forum.dynare.org/uploads/default/original/2X/9/9928a98376e84af3f976a1a69beab583cec5b3af.png)

ERROR

 ![image](https://forum.dynare.org/uploads/default/original/2X/0/091bb5e1f1b67818902de4405848bc4e51c046f4.png)

Many thanks

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [27 May 2019 18:46 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/32 "2019-05-27T18:46:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AITANAgf](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@AITANAgf](https://forum.dynare.org/u/AITANAgf)\
**Post date:** [29 May 2019 18:08 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/33 "2019-05-29T18:08:49Z")

</div>

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](https://forum.dynare.org/uploads/default/original/2X/4/4d0d4a21eb8a832f29c1bac4cb55b6819b1670ad.m) (842 Bytes)  
[departshock1.mod](https://forum.dynare.org/uploads/default/original/2X/3/36ca1403b4a7fcdc79b172f3f78d3bc5fa02683c.mod) (3.1 KB)  
[macroproject.mod](https://forum.dynare.org/uploads/default/original/2X/8/8b48e5d5c6074b502a12d3580025c6d104eead4f.mod) (3.4 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [30 May 2019 19:10 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/34 "2019-05-30T19:10:04Z")

</div>

It should be

```auto
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

```

---

<div class="post-metadata">

**Author:** ![AITANAgf](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@AITANAgf](https://forum.dynare.org/u/AITANAgf)\
**Post date:** [30 July 2019 16:40 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/35 "2019-07-30T16:40:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [31 July 2019 09:01 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/36 "2019-07-31T09:01:18Z")

</div>

What is the error message?

---

<div class="post-metadata">

**Author:** ![AITANAgf](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@AITANAgf](https://forum.dynare.org/u/AITANAgf)\
**Post date:** [3 August 2019 14:30 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/37 "2019-08-03T14:30:57Z")

</div>

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

```auto
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) ;**

```

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [4 August 2019 11:29 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/38 "2019-08-04T11:29:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AITANAgf](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@AITANAgf](https://forum.dynare.org/u/AITANAgf)\
**Post date:** [4 August 2019 11:48 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/39 "2019-08-04T11:48:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [4 August 2019 12:11 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/40 "2019-08-04T12:11:12Z")

</div>

I am saying that

```auto
        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

```auto
        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) ;

```

[Previous page](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609.md?page=1)

[Next page](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609.md?page=3)
