# Pruning and Euler residuals

Hi Johannes,

When you have a minute, I have two related questions based on comparisons between the solution provided by Dynare’s perturbations and a projection method I am doing for one of my papers. As we are aware, second order perturbations can lead to explosive simulations. Although I can compute the cross correlations of my simulated endogenous variables produced by the stoch_simul command, when I try to simulate starting from the steady state (not using the simulated values Dynare automatically produced) in order to compute the Euler residuals, I encounter an explosive solution. Therefore, I was using the pruning technique suggested by Fernandez. In particular, it looked like:

stoch_simul(periods=1000, drop=200, solve_algo=0, order=2, nograph, noprint);
simulations=pruning_abounds(M_,options_,order=2,‘kim_et_al’);

However, upon that format and other alterations, I could not get it to work. I looked extensively online, but no sample code seems to exist publicly. What should I change to prune my second order perturbation?

Related to that, are you aware of documentation on computing Euler residuals? I have a method where I essentially construct the equations as they are articulated in Judd’s paper, but I was interested in comparing if there’s other code available. I saw some material from Wouter Den Haan, but it’s hard to read without a pdf of the model and what each line of code is derived from.

Thank you as always for your help!

For the reference, I would have to look.

Why don’t you use Dynare’s pruning option, which is the Kim et al one?

Indeed, that was the one I was trying to use via Fernandez’s package; I wasn’t able to find any documentation by Dynare on it – just his package that goes with it. However, the code and lots of variations of it that are in the readme did not work.

Just to clarify, I am still unsure about how to do pruning in Dynare. Although it is noted in the manual, the command “pruning=1” and variants of it do not work for me. Any suggestions on the computation of Euler residuals would also be helpful!

In Dynare 4.4.2 the correct Kim et al/Andreasen et al pruning is conducted whenever you use pruning=1. Which type of problem do you encounter?

Regarding Euler errors, the only source I can come up with on top of my head is the Fortran code of Aruoba et al (2006): “Comparing solution methods for dynamic equilibrium economies” at economics.sas.upenn.edu/~jesusfv/companion.htm But this requires some digging. I always wanted a Matlab version of that code. So if you go ahead an succeed, I would be grateful if you could share it.

Thank you for the reply! I attached the file – it’s very similar to what you’ve already seen in my file before; just note at the bottom that pruning is included in the options. If I instead use “pruning=1”, Dynare encounters an error. In particular, it says “DYNARE: preprocessing failed”. I have tried various alterations to that command.

If I can get the pruning to work, I should have a working Euler residual code – at least one version that computes it; I will gladly share it with you/ others after I get it working in my paper (and tested). I was just curious how others computed their accuracy – but it seems documentation of these methods is just so scarce. Thanks for the other reference too, which I will check, though not familiar with Fortran.
benchmarkcb.mod (4.32 KB)

The syntax to enable pruning is just

```stoch_simul(order=2,pruning); ```
and not

```stoch_simul(order=2,pruning=1); ```

Right, I tried that too, but when I simulated my time series it still exploded. (That’s why I thought I was doing it incorrectly.) I’ll send you a message with details.

Hi Johannes,

Adding to our last email conversation: One peculiarity that I encountered is that my simulated time series explodes sometimes, and other times it does not – I am not sure what causes it to happen. (I have pruning on each case.) I implemented what you suggested – using Dynare’s simult_ command – via code you posted in another thread:
[dr,~,M,~,oo] = resol(0,M_,options_,oo_);

However, to calculate the dynamic Euler residuals, I need to use Gauss Hermite; using the two node example I showed you before, it might take the form of
y_plus = SS + A*(ye2(:, t) - SSe) + Bshocks(:,t);
y_minus = SS + A
(ye2(:, t) - SSe) - B*shocks(:,

With that in mind, two clarifying questions:

1. Why does simult_ produce time series that do not explode, but when I apply the decision rules (see the bottom of this message), it explodes?
2. Is there a way to incorporate simult_ to do Gauss Hermite quadrature? I googled “simult_” and literally only one other dynare thread comes up – no one seems to use it!

Example of decision rules:
for t = 2:Tsim;
y_2(:,t)=SS+.5del2+A(ye2(:,t-1)-SSe)+Bshocks(:,t) …
+.5
Ckron(ye2(:,t-1)-SSe,ye2(:,t-1)-SSe) …
+.5
Dkron(shocks(:,t),shocks(:,t))+Ekron(ye2(:,t-1)-SSe,shocks(:,t));
ye2(:,t)=y_2(statevars,t);
end

What you need is the value of the policy function given today’s state and new period’s shock, with the shock once being positive and once being negative. This can be easily done using simult_. simult_ has a syntax where you provide the initial condition and the shocks. From the “pure news shock” model on my homepage:

``````//initialize IRF generation
initial_condition_states = repmat(oo_.dr.ys,1,M_.maximum_lag);
shock_matrix = zeros(options_.irf,M_.exo_nbr); %create shock matrix with number of time periods in colums

// set shocks for pure news
shock_matrix(1,strmatch('eps_z_news',M_.exo_names,'exact')) = 1; %set news shock to 1 (use any shock size you want)
y2 = simult_(initial_condition_states,oo_.dr,shock_matrix,1);
y_IRF = y2(:,M_.maximum_lag+1:end)-repmat(oo_.dr.ys,1,options_.irf); %deviation from steady state``````

Thus, you need to call simult_ twice, once with a positive shock and once with a negative shocks. It will provide you with the policy function value for all variables. You also only need to simulate for one period instead of oo_.irf periods.

The difference by the way is that your policy functions do not implement pruning. You do not have an augmented state space there.

I am always amazed at how well you know this software! I think I followed your suggestion properly. Since the y_2 in the following code is what explodes, I just replace it with “policyfunc”, which is equivalent to the y_2 in your quoted code. The accuracy of the solution doesn’t look that great, so I am also in the process of coding my model up in GSSA. Just so much harder to do analysis in it… writing IRFs by hand, etc!

for t = 2:Tsim;
y_2(:,t)=SS+.5del2+A(ye2(:,t-1)-SSe)+Bshocks(:,t) …
+.5
Ckron(ye2(:,t-1)-SSe,ye2(:,t-1)-SSe) …
+.5
Dkron(shocks(:,t),shocks(:,t))+Ekron(ye2(:,t-1)-SSe,shocks(:,t));

``````y_2(:,t)=policyfunc(:,t);
ye2(:,t)=y_2(statevars,t);
``````

end

I don’t understand what you are doing. You are supposed to use the y_2 as the whole policy function. It already is the full pruned solution that must be entered in evaluating the expectation

Right – I didn’t post that part of my code since I didn’t want to take more of your time, but that’s what I am doing: use the simulated “simult_” as the policy function, instead of what I would have otherwise done to create the policy function via Dynare’s oo_.dr.ghx etc variables (what you saw above). Once that ye2 is created, then I can set up two quadrature nodes (i.e. below) and evaluate expectations.

``````    y_plus = SS + A*(ye2(:, t) - SSe) + B*shocks(:,t);
y_minus = SS + A*(ye2(:, t) - SSe) - B*shocks(:,t);``````

I still don’t get it. The result of simult_ is the full right-hand side, including the shock response. It looks as if you are using the shock a second time.