# IRF second order with large shock, Dynare 4.2.1

**URL:** <https://forum.dynare.org/t/irf-second-order-with-large-shock-dynare-4-2-1/2439>\
**Category:** Stochastic simulations\
**Created:** [3 April 2012 09:27 UTC](https://forum.dynare.org/t/irf-second-order-with-large-shock-dynare-4-2-1/2439 "2012-04-03T09:27:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![616Dynare](https://forum.dynare.org/letter_avatar_proxy/v4/letter/6/bc8723/32.png) [@616Dynare](https://forum.dynare.org/u/616Dynare)\
**Post date:** [3 April 2012 09:27 UTC](https://forum.dynare.org/t/irf-second-order-with-large-shock-dynare-4-2-1/2439/1 "2012-04-03T09:27:06Z")

</div>

Hi,

I tried to replicate the IRF of Dynare 4.2.1 for 2nd-order approximation, using Dynare’s policy functions. It seems to be fine for small shocks, but for large shocks there is a difference between Dynare-based irfs and irfs computed using Dynare’s policy functions (I eliminate the issues regarding the seed, drop periods, etc. by fixing the seed for random numbers and looking at only one shock). I attach the Dynare file and a file that computes the IRFs and plots the differences. There are even small differences for the shock process (z), which seems particularly strange. Am I just being silly and overlooking something?

Thanx a lot!

P.S.: In fact, e1 in Dynare’s irf is 0.070000000000071. Shouldn’t it be just 0.07 if the shock is 0.07?  
P.P.S.: To follow up: Controlling for the seed within the .mod file does not seem to work. If I control for the random number seed in Dynare’s irf.m file (just before ex1(:,i\_exo\_var) = randn(long+drop,nxs)\*chol\_S;), then this guarantees that Dynare’s and my IRFs are based on exactly the same random numbers. However, the issue with e1 remains - the shock size in Dynare is slightly different (e1=0.070000000000071 instead of 0.07). I guess this is a numerical issue, but it might nevertheless be annoying if one wants to compare accuracy…  
[IRF2nd\_SimpleGrowth.m](https://forum.dynare.org/uploads/default/original/2X/1/1c9b6cd08a312553dbda413b5b2f2f4c98090c51.m) (2.62 KB)  
[SimpleGrowth.mod](https://forum.dynare.org/uploads/default/original/2X/3/3057b80c668588a1998e81b6845cf541f52a29f3.mod) (644 Bytes)

---

<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:** [18 April 2012 19:01 UTC](https://forum.dynare.org/t/irf-second-order-with-large-shock-dynare-4-2-1/2439/2 "2012-04-18T19:01:20Z")

</div>

Your problem is line 154 of stoch\_simul. To avoid problems with semidefinite covariance matrices, Dynare adds 1e-14 to the covariance matrix:

` SS(M_.exo_names_orig_ord,M_.exo_names_orig_ord)=M_.Sigma_e+1e-14*eye(M_.exo_nbr);
`  
before doing a Cholesky decomposition. If you comment out the plus part, everything should be fine.

---

<div class="post-metadata">

**Author:** ![616Dynare](https://forum.dynare.org/letter_avatar_proxy/v4/letter/6/bc8723/32.png) [@616Dynare](https://forum.dynare.org/u/616Dynare)\
**Post date:** [25 April 2012 14:54 UTC](https://forum.dynare.org/t/irf-second-order-with-large-shock-dynare-4-2-1/2439/3 "2012-04-25T14:54:19Z")

</div>

Excellent! Thank you very much!
