# Gathering multiple IRFs

**URL:** <https://forum.dynare.org/t/gathering-multiple-irfs/3445>\
**Category:** Dynare help (legacy posts)\
**Created:** [14 October 2013 17:44 UTC](https://forum.dynare.org/t/gathering-multiple-irfs/3445 "2013-10-14T17:44:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbt](https://forum.dynare.org/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@nbt](https://forum.dynare.org/u/nbt)\
**Post date:** [14 October 2013 17:44 UTC](https://forum.dynare.org/t/gathering-multiple-irfs/3445/1 "2013-10-14T17:44:59Z")

</div>

Hi,

is there a possibility to repeat one AR(1) shock multiple times in the same model and then plot the the frequency distribution of the highest deviation of a control variable from steady state (like the aggregate IRF)?

Best regards,  
nbt

---

<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:** [14 October 2013 19:54 UTC](https://forum.dynare.org/t/gathering-multiple-irfs/3445/2 "2013-10-14T19:54:09Z")

</div>

Note that this only makes sense at higher order. At first order, the IRFs will always be the same due to linearity.  
If you want to do this at higher order, it requires you hacking the irf.m function of Dynare. Instead of averaging over different IRFs you need to store the individual draws.

---

<div class="post-metadata">

**Author:** ![nbt](https://forum.dynare.org/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@nbt](https://forum.dynare.org/u/nbt)\
**Post date:** [15 October 2013 14:13 UTC](https://forum.dynare.org/t/gathering-multiple-irfs/3445/3 "2013-10-15T14:13:27Z")

</div>

thanks. I just tried doing it by hand, that is simulating the model repeatedly and storing the entry in the oo\_/irfs. Why does the shock response always look the same? I thought in each simulation there would be a random shock imposed?

How would you manipulate the irf.m file to store the irfs? It would take me too long to get acquainted with the code in detail, time I havent got ![:mrgreen:](https://forum.dynare.org/uploads/default/original/1X/15680453330e74f929b585a237613f0bdf61e069.gif "Mr. Green") Would really appreciate 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:** [22 October 2013 10:09 UTC](https://forum.dynare.org/t/gathering-multiple-irfs/3445/4 "2013-10-22T10:09:35Z")

</div>

No. The concept used is a generalized IRF. At first order, the IRFs will always be the same due to linearity. If you tried higher order, did you use a different seed for generating random shocks (see the manual)?

It should be sufficient to replace

` for j = 1: replic
        ex1(:,i_exo_var) = randn(long+drop,nxs)*chol_S;
        ex2 = ex1;
        ex2(drop+1,:) = ex2(drop+1,:)+e1';   
        y1 = simult_(temps,dr,ex1,iorder);
        y2 = simult_(temps,dr,ex2,iorder);
        y = y+(y2(:,M_.maximum_lag+drop+1:end)-y1(:,M_.maximum_lag+drop+1:end));
    end
    y=y/replic;
`  
by

` for j = 1: replic
        ex1(:,i_exo_var) = randn(long+drop,nxs)*chol_S;
        ex2 = ex1;
        ex2(drop+1,:) = ex2(drop+1,:)+e1';   
        y1 = simult_(temps,dr,ex1,iorder);
        y2 = simult_(temps,dr,ex2,iorder);
        y = y+(y2(:,M_.maximum_lag+drop+1:end)-y1(:,M_.maximum_lag+drop+1:end));
        y_all(:,:,j)=y;
    end
    save IRFs y_all
    y=y/replic;
`  
However, this is only a dirty hack without initialitizing y\_all

---

<div class="post-metadata">

**Author:** ![nbt](https://forum.dynare.org/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@nbt](https://forum.dynare.org/u/nbt)\
**Post date:** [22 October 2013 12:39 UTC](https://forum.dynare.org/t/gathering-multiple-irfs/3445/5 "2013-10-22T12:39:59Z")

</div>

Thank you Jpfeiffer. I think my problem is quite similar to this post ([Are Dynare's stochastic shocks truely random?](https://forum.dynare.org/t/are-dynares-stochastic-shocks-truely-random/2035/1)).  
I know now that I have to add set\_dynare\_seed=(…) to the options of stoch\_simul(…) instead of simul\_seed (which seems to be outdated).  
In the description of set\_dynare\_seed I see that there are two input argument a,b which correspond to the random number generator and its seed respectively.  
According to the dynare manual one can also only put a single integer or double or expression in the argument set\_dynare\_seed(.).  
But how exactly do I use this option. When I used 1 as an integer I got an error message on the mod file:  
ERROR: BA\_Perturbation\_General.mod:40.45-59: syntax error, unexpected NAME

Thanks for your help,  
nbt

---

<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:** [22 October 2013 13:27 UTC](https://forum.dynare.org/t/gathering-multiple-irfs/3445/6 "2013-10-22T13:27:21Z")

</div>

Without the mod-file I cannot tell.

---

<div class="post-metadata">

**Author:** ![nbt](https://forum.dynare.org/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@nbt](https://forum.dynare.org/u/nbt)\
**Post date:** [22 October 2013 17:09 UTC](https://forum.dynare.org/t/gathering-multiple-irfs/3445/7 "2013-10-22T17:09:58Z")

</div>

ups sry  
[BA\_Perturbation\_General.mod](https://forum.dynare.org/uploads/default/original/2X/f/fd04b86a26808096c956aee4d9ac9edaf450d4da.mod) (2.04 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:** [4 November 2013 09:23 UTC](https://forum.dynare.org/t/gathering-multiple-irfs/3445/8 "2013-11-04T09:23:16Z")

</div>

set\_dynare\_seed is a standalone command. It is not an option of stoch\_simul
