# Second order approximation and the IRF explosive

Dear Prof. Jpfeifer,

I am trying to numerically calculate the expected values of welfare for different policy specifications and compare those to one another. So I use a second order approximation to all the equilibrium conditions, including the recursive representation of welfare, which is just thhousing1.mod (6.6 KB)
e utility of the households as in the literature.

My code runs well, however, when I set “order=2”, I encounter the following message:

stoch_simul:: The simulations conducted for generating IRFs to epsa_c were explosive.
stoch_simul:: No IRFs will be displayed. Either reduce the shock size,
stoch_simul:: use pruning, or set the approximation order to 1.

What does it mean? If it is a problem, how can I fix it?

Besides, I also want to search over a grid over the parameter ranges, like [0,1], and set the grid step for each parameter, for example, 0.1, in order to find the optimal policy coefficients. How can I do this in Dynare?

Code attached.

I use an option pruning in stoch simul to remedy the explosiveness. But somet8mes it seems prunin* nearl6 reproduces first oder results.

1. You should reduce your shock size. `0.1` mean 10 percent.
2. Use theoretical moments for welfare evaluation
3. For a grid search, follow e.g. Policy frontier and the general discussion at Loop over parameters

Dear Prof. Jpfeifer,

Thanks for your reply. The post you pointed to is very helpful. And I can run the 2nd order approximation well when I reduce the shock size to 0.01.

However, for the code you posted in Policy frontier, it uses the command “osr” which is designed for the linear-quadratic problem. What I want to do is to find the values of the optimal policy coefficients which can maximize the welfare. The welfare is defined as a variable as the utility of the household. I have clearly written the model in level and the steady states. The parameter values of the policy rule do Not impact the steady states. I think I might have to write a function which can solve the maximization problem based on the function of welfare, but I don’t know how to do it in Dynare. Could you please help me with it?

Dear all,

Could anyone please help me with this question? I just want to compare the welfare which is defined as the household utility, under different policy rules. I don’t mean to derive a welfare loss function and solve the linear quadratic problem. So now I was stuck that I don’t know how to find the optimal parameters of the policy rule in Dynare.

You could work along the lines of https://github.com/JohannesPfeifer/DSGE_mod/tree/master/Born_Pfeifer_2018/Welfare

Prof. Jpfeifer,

Thanks for your reply. I followed some posts in this forum and wrote the attached code. The mod. file runs well, however, the parameter loop file run into the error message:
stoch_simul:: The simulations conducted for generating IRFs to epsa_d were explosive.
stoch_simul:: No IRFs will be displayed. Either reduce the shock size,
stoch_simul:: use pruning, or set the approximation order to 1.

How should I fix this problem? I have already reduced the shock size to 0.001.

Besides, if the parameter loop file looks correct, how can I find the maximized welfare and parameter value?

housing.mod (6.6 KB)

Why do you need IRFs in the first place if you are interested in welfare?

Dear Prof. Jpfeifer,

I shut down the IRFS and now I can run the code without any error message. However, could you please help me check whether my parameter loop file was written correctly? If it looks fine, how can I find the maximized welfare and parameter value?

Thank for your time. I am looking forward to your reply. Here attached the updated code file.optimal_rule.m (556 Bytes)
housing.mod (6.6 KB)

Hi Jpfeifer,

Could you please spare some time and help me with this question?

Thank you very much!

The parameter loop looks fine. But what do you now mean with

?
You mean where to find welfare in the saved `oo_`-structure?

Dear Prof. Jpfeifer,

Thanks for your feedback. Through looping the parameters, I want to search over a grid over the parameter ranges, for example [0,1], in order to find the optimal policy coefficients. The “optimal” refers to the maximized welfare given the “optimal” parameter value. The welfare is defined as the household utility. Because I think during the parameter loop, Dynare must generate many welfare values given different parameter values. So if the parameter loop looks fine, how can I find the maximized welfare value and the corresponding parameter value which generate the maximized welfare?

Please be more precise and specific with respect to your particular mod-file. Which variable encodes welfare. And what is the relation between the

and

If I understand it correctly, for each parameter value on the grid, you want to run an optimizer over a different set of parameters. What are these parameters you want to optimize over?

Dear Jpfeifer,

Thanks for your reply. Your understanding is correct. What I want to do is find the the maximized welfare value and the corresponding parameter value which can generate the maximized welfare. The parameters which I want to optimize over is rho_pi and rho_y, which are the coefficients of the Taylor rule. The welfare variables in the mod file are v_b, v_s, and v, which represent the borrowers’, savers’, and the aggregate utility, respectively.

Sorry for the delay, but these weeks are really busy.
You need to write an objective function passing in the parameters that you are optimizing over, set these parameters, solve the model, and output the welfare measure you want. An example of this would be https://github.com/JohannesPfeifer/DSGE_mod/blob/master/Born_Pfeifer_2018/Welfare/get_consumption_equivalent_unconditional_welfare.m
In your case, the input argument would be a vector.

A rough outline would be at

1 Like

Dear Prof. Jpfeifer,

Thanks for your help. I followed your shared post Optimal policy parameters in a non-linear model. I just modify a little bit since I only have two parameters which need to be optimized. However, when I run the mod-file, I get the error message:

Undefined function or variable ‘par_value_lambda’.

Error in welfare_objective (line 19)
outvalue=1e5+par_value_lambda^2;

Error in csminwel (line 62)
f0 = fcn(x0,varargin{:});

Error in housing (line 341)
[fhat,x_opt_hat] = csminwel(@welfare_objective,x_start,H0,[],crit,nit,x_opt_name);

Error in dynare (line 223)
evalin(‘base’,fname) ;

Could you please help me check my code and see how to fix the problem? welfare_objective.m (703 Bytes)
housing.mod (7.2 KB)

There were a couple of mistakes in my original post I corrected. A running version is attached.
welfare_objective.m (713 Bytes)
housing.mod (7.1 KB)

Dear Prof. Jpfeifer,

Many thanks for your generous help. It helped me a lot!

I notice that you didn’t put the stoch_simul command in the mod-file. However, in the post Optimal policy parameters in a non-linear model, you indicated me that the maximization code should be put after a stoch_simul-command because that one is needed to initialize all the structures used. Could you please help me explain whether should I put the maximization code right after the stoch_simul command or just delete it? And why？

Besides, how can I set the grid step during the process of optimal parameter value search? For example, I define the range of the parameters to be optimized as 0 to 3, rather than 0 to Inf in your posted code, and I also want to set the grid search step is 0.01 during this range. How can I do it in dynare?

1. The safe option is to have a `stoch_simul`-command in the mod-file, but when I tested the code, it was not necessary.