# 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:** 3

<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 13:08 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/41 "2019-08-04T13:08:33Z")

</div>

> [@jpfeifer](#):
>
> ```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) ;
> 
> ```

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, ‘;’));

---

<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:** [7 August 2019 18:18 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/42 "2019-08-07T18:18:02Z")

</div>

Please provide the `fixednewconresults.mat`

---

<div class="post-metadata">

**Author:** ![Faro](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/49beb7/32.png) [@Faro](https://forum.dynare.org/u/Faro)\
**Post date:** [25 October 2019 15:56 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/43 "2019-10-25T15:56:38Z")

</div>

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](https://forum.dynare.org/uploads/default/original/2X/b/bf55f6eecaa7ce6dedb1d63f63d5c3f436b42101.jpeg)

My plot with the matlab code looks much better, but for that I coded everything: ![discretion](https://forum.dynare.org/uploads/default/original/2X/8/841be6deb4679d99f05419286f29479ba10a59f5.jpeg)

> 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?

---

<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:** [28 October 2019 10:53 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/44 "2019-10-28T10:53:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Faro](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/49beb7/32.png) [@Faro](https://forum.dynare.org/u/Faro)\
**Post date:** [29 October 2019 10:20 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/45 "2019-10-29T10:20:50Z")

</div>

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?

---

<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:** [29 October 2019 10:50 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/46 "2019-10-29T10:50:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![songyao](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@songyao](https://forum.dynare.org/u/songyao)\
**Post date:** [29 October 2019 13:47 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/47 "2019-10-29T13:47:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Faro](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/49beb7/32.png) [@Faro](https://forum.dynare.org/u/Faro)\
**Post date:** [31 October 2019 17:40 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/48 "2019-10-31T17:40:17Z")

</div>

Thanks it works now!!

---

<div class="post-metadata">

**Author:** ![feryb](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/a183cd/32.png) [@feryb](https://forum.dynare.org/u/feryb)\
**Post date:** [15 November 2019 13:39 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/49 "2019-11-15T13:39:53Z")

</div>

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

---

<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:** [17 November 2019 08:23 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/50 "2019-11-17T08:23:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![feryb](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/a183cd/32.png) [@feryb](https://forum.dynare.org/u/feryb)\
**Post date:** [25 November 2019 16:18 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/51 "2019-11-25T16:18:42Z")

</div>

Professor Pfeifer,

Thank you

Best

---

<div class="post-metadata">

**Author:** ![vogel](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/e95f7d/32.png) [@vogel](https://forum.dynare.org/u/vogel)\
**Post date:** [23 November 2020 16:14 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/52 "2020-11-23T16:14:16Z")

</div>

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](https://git.dynare.org/Dynare/dynare/-/merge_requests/1767) or some failure by me?

Thank you in advance  
[ompD.mod](https://forum.dynare.org/uploads/short-url/aQxbf1wzVpPSnAYLSPh4fHIYnPh.mod) (754 Bytes) [ompDirfs.m](https://forum.dynare.org/uploads/short-url/gv1I7rZOvWygtlXs0F2SxBN14e7.m) (1.1 KB)  
(ompD1/2/3 are just line 25 with “epsu(-1/-2/-3)”)

---

<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:** [24 November 2020 11:53 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/53 "2020-11-24T11:53:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vogel](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/e95f7d/32.png) [@vogel](https://forum.dynare.org/u/vogel)\
**Post date:** [24 November 2020 14:05 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/54 "2020-11-24T14:05:41Z")

</div>

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

---

<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:** [25 November 2020 20:24 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/55 "2020-11-25T20:24:06Z")

</div>

What is the error message you are getting?

---

<div class="post-metadata">

**Author:** ![vogel](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/e95f7d/32.png) [@vogel](https://forum.dynare.org/u/vogel)\
**Post date:** [26 November 2020 12:20 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/56 "2020-11-26T12:20:12Z")

</div>

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"

---

<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:** [26 November 2020 13:24 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/57 "2020-11-26T13:24:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vogel](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/e95f7d/32.png) [@vogel](https://forum.dynare.org/u/vogel)\
**Post date:** [26 November 2020 20:32 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/58 "2020-11-26T20:32:38Z")

</div>

Thanks alot Prof. Pfeifer!

---

<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:** [20 December 2020 08:55 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/61 "2020-12-20T08:55:21Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![vd111](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/49beb7/32.png) [@vd111](https://forum.dynare.org/u/vd111)\
**Post date:** [20 December 2020 18:50 UTC](https://forum.dynare.org/t/q-combining-irfs-into-subplotted-figures-iterating/3609/62 "2020-12-20T18:50:14Z")

</div>

Thank you for your reply. I have tried doing that in [combinedmodel.m](https://forum.dynare.org/uploads/short-url/6nDy0O5qTmMnulHLd0PqiAIIvsO.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.

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

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