Pruning with third order perturbation/ GIRFs


I am looking at the discrete model from Dewachter and Wouters 2014 (Endogenous risk in a DSGE model with capital-constrained financial intermediaries), who have a non-linear constraint and use third order perturbation in Dynare. And I have some problems understanding/using the pruning function correctly.

When I simulate their model using third order perturbation and no-pruning, I get good simulation results that do not show any strange behaviour. However when I then try to do a GIRF, I get a GIRF that is exploding in most variables. Now I understand that I should use pruning to prevent such explosive behaviour, but if I use pruning in my simulations, my variables are not well-behaved and have bigger range and move far away from the deterministic steady state.
Is there anything I’m missing in using pruning with third order perturbation? Is there a way to not do pruning for the simulations but do it for the GIRF?


In that case, you can use the simult_-function to generate GIRFs yourself. There you can select whether you want pruning or not. But more fundamentally, you should either work with pruning all of the time or not at all. And how can the GIRFs explode?

I am using the simult_ - function based on your RBC_state_dependent_GIRF.mod example. Here, however if I try to set options_.pruning=1; I get an error-message (which I think makes sense since I haven’t used pruning for the simulations).

Right now, my GIRFs turn very large in the sixth period after the shock (and then into NaNs), which is what I thought I could prevent with pruning. And I understand completely that I should be consistent throughout the model, but the simulations only feature the model characteristics (as documented by Dewachter and Wouters) in the unpruned setting.

Thanks a lot,

I would need to see the problematic codes.

Yes, sure!

oneassetmodelcopy.mod (7.8 KB)


An update on my situation: I’m trying to make GIRFs based on Basu & Bundick 2017 ( This method sort of works to calculate GIRFs. However, it only works if I don’t use pruning and keep the shock small/ the number of simulations small.

Now, I do understand that pruning should help when I want to increase the shock-size/ the number of simulations. However, when I do use pruning, I am back to my problem above where the non-linearities are removed from the simulation and the GIRFs (and the simulation is more dispersed and the economic interpretation of some variables seems to be reduced (e.g. leverage in the non-pruned model ranges from 200 to 400%, but in the pruned model from -1000 to 400%)).

My question now is whether this is a wanted feature of pruning - that it removes the non-linearities and that it reduces any economic interpretation one could make?


(The code with the B&B2017 GIRFs attached)
oneassetmodel2copy.mod (7.3 KB)

  1. Basu and Bundick did not really use GIRFs, they compute the IRFs at the stochastic steady state, which is a very particular conditioning set for the GIRFs.
  2. No, pruning creates a whole bunch of problems. But we accept them to avoid explosive simulations. Note that the IRFs at the stochastic steady state should be a lot more stable than normal GIRFs, so you could work without pruning even for larger shocks. Also not that you do not need several simulations as there is nothing to integrate out. One simulation suffices.


I’m following Professor Pfeifer and use the following source code as an example to plot the IRFs.

In my work with two production sectors and small open economy, I have an uncertainty shock to the TFPs. The market clearing equation of tradable good is Y_t=C_t+IT_t+IN_t+TB_t. Where IT_t, IN_t, TB_t are the investments in two sectors and the trade balance. However, the plotted IRF is really hard to be explained. Facing the uncertainty shock, consumption and investment, as well as trade balance drop. Yet, the output goes up. Is it possible to have such a scenario?


Do you work in levels or in logs? If the latter, then it might be related to the approximation. Or are there adjustment costs missing?

Dear Professor Pfeifer,

Thanks for your reply. I work in levels with the following simulation command.

And I have the capital adjustment cost. The model could be with nominal rigidities. And the price adjustment cost will enter the market clearing condition of output: Y_t=IT_t+IN_t+TB_t+C_t+Adj.Cost

However, the IRFs are similar to the ones presented here. In this case, do you have any suggestion on how to solve this problem?


But your IRFs clearly state “percent” next to the axes. How did you get the percentages?

Dear Professor

Maybe I misunderstand your suggestion. The simulation works in level. And this GIRF is based on the stochastic steady state. And the IRF is the percentage deviated from this stochastic steady state. I borrow the following source code for the computation of GIRF.

Do you mean that this approximation method could lead to the problem I faced? If I want to check whether it is really due to this approximation method. Do you have any suggestion on other methods to get the IRF in this third-order environment.


Referring to that mod-file, you need to check whether the IRFs of the levels like Y are consistent. My hunch is you are looking at log_Y.

Dear Professor Pfeifer,

Thanks for your suggestion. I go back to my code and check whether I use log_Y or Y. Currently, my code uses Y but not log_Y in the model part of the mode file. I attach the part of my mod file to generate the IRF.

stoch_simul(order=3,k_order_solver,noprint,irf=0,nofunctions) y_t iN_t iT_t c_t tb_t;

// IRF, following Basu and Bundick (2017)
y_pos = strmatch(‘y_t’,M_.endo_names,‘exact’);
in_pos = strmatch(‘iN_t’,M_.endo_names,‘exact’);
it_pos = strmatch(‘iT_t’,M_.endo_names,‘exact’);
c_pos = strmatch(‘c_t’,M_.endo_names,‘exact’);
tb_pos = strmatch(‘tb_t’,M_.endo_names,‘exact’);


shock_mat_with_zeros=zeros(burnin+IRF_periods,M_.exo_nbr); %shocks set to 0 to simulate without uncertainty
IRF_no_shock_mat = simult_(oo_.dr.ys,oo_.dr,shock_mat_with_zeros,options_.order)’; %simulate series
stochastic_steady_state=IRF_no_shock_mat(1+burnin,:); % stochastic_steady_state/EMAS is any of the final points after burnin
shock_mat = zeros(burnin+IRF_periods,M_.exo_nbr);
shock_mat(1+burnin,strmatch(‘e_sigma’,M_.exo_names,‘exact’))= 1;
IRF_mat = simult_(oo_.dr.ys,oo_.dr,shock_mat,options_.order)’;
IRF_mat_percent_from_SSS = (IRF_mat(1+burnin+1:1+burnin+IRF_periods,:)-IRF_no_shock_mat(1+burnin+1:1+burnin+IRF_periods,:))./repmat(stochastic_steady_state,IRF_periods,1); %only valid for variables not yet logged

%scale IRFs as reqired, Figure 1
y_vola_IRF = 100IRF_mat_percent_from_SSS(:,y_pos);
in_vola_IRF = 100
id_vola_IRF = 100IRF_mat_percent_from_SSS(:,it_pos);
c_vola_IRF = 100
tb_vola_IRF = 100*IRF_mat_percent_from_SSS(:,tb_pos);

Please kindly correct me if I’m wrong.


Then those results are indeed strange. The linear resource constraint should still hold