Help looping over two parameters

Hi all,

I’m trying to loop over two parameters by first running dynare and then looping over the stoch_simul command. Before each stoch_simul loop, I load in two new parameters.

For some reason, there are no errors and matlab takes into both new parameters each time, but I can see from the results that only one of the parameter change is being taken into account (ppsipi). The other parameter (ppibar) is being updated, but the I keep getting the same results implying that it is in fact not being updated…

Any help would be greatly appreciated.

Jae

You are not taking parameter dependence into account. That’s why you should use model-local variables (the ones with the pound operator) or a steady state file. See Remark 4 (Parameter dependence and the use of model-local variables) in Pfeifer (2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models”

Thanks for the reply Johannes.

Just trying to understand what dynare does…in my loop I update my parameter of choice, then run an m-file that re-defines the rest of the parameters based on the changes and saves it, then dynare runs my mod file which loads and sets all the parameters each time.

Why does this logic not work if I am re-uploading the whole set of parameters each time…? Is because I am running stoch_simul instead of the whole dynare?

Also, I tried following your suggestion of creating a steady state file. I think I’m struggling to wrap my head around how to do this when I recall steady state values in my model block (like in my Taylor rule).

I’m using the attached version and getting a “steadystate file did not compute the steadystate” error…
MSDSGE_level_loop_short_steadystate.m (1.9 KB)

Where do you all get these old, outdated, and error-prone steady state files from? Its structure is deprecated since ancient times and an up-to-date example is delivered with every Dynare installation in the examples folder (NK_baseline_steady_state.m). But in your case, this is unnecessary as shown below.

To your question. The problem is the following. You have e.g.

parameters eeta Y_SS

and

set_param_value('eeta',eeta); ... // Analytic Steady State Y_SS = ((eeta-1)/eeta)^(1/ttau)*gbar;
Obviously, the parameter Y_SS depends on eeta. But when you change eeta, you do not automatically change Y_SS with it. This is why you should use model-local variables or a steady state file to handle this dependence. In your case, I would recommend using a simple steady_state_model block, which automatically creates the corresponding steady state file. You simply need to move the I attach the corresponding file.

Lastly, one remark: you are using a linearized model. order=2 will be useless in this case and welfare evaluations usually wrong.
MSDSGE_level_loop_short.mod (4.24 KB)

thanks again for your reply. I didn’t realize these steady state files were outdated. I got them from Chris Sim’s lecture notes.

Would you be able to elaborate on your last remark there? What do you mean by my using a linearized model and order=2 being useless? I did want to do welfare evaluations eventually.

You cannot do welfare computations on a purely linearized model. You should use a second order approximation. At a minimum, if certain conditions are met (see Woodford (2002)), a linear-quadratic approach might be sufficient.

Sorry Johannes, I don’t think I follow.

I thought with order=2 dynare is doing a second order approximation already. It was my understanding that inserting a welfare function into the model and using order=2 to do welfare analysis is common practice.

Am I missing something here? what is the difference between dynare order=2 and your suggestion of “use a second order approximation”?

If your model is already linearized, a second order approximation of these equations will be equal to a linear approximation, because you lost the second order terms already when entering the equations linearly. You can still append the objective function nonlinearly and you will get a second order approximation of the objective. But this linear quadratic approach is only valid under particular restrictions (e.g. undistorted steady state). In general, it will be false.

Right. That makes sense.

What I’m confused about is why you think my model is already linearized. The model block contains my FOCs in its raw form.

Sorry, my mistake. I only read the heading

[quote]// model in logs
[/quote]

in your file and presumed it was log-linearized. I should have looked more closely.

Sorry for the confusion. My file could have been neater…

Thanks so much for the all your comments and suggestions!

Hi everyone,
Let me continue on this topic, as I used the same approach to loop over 2 parameters, yet in a different model.
My question is what exactly stoch_simul(var_list_) does. Because my output matrix X delivers the wrong results, except the very first iteration (column 1 of X). Two parameters, which I am looping over (phiinf, phier), do not affect other parameters like it was in the previous case. Yet it is obvious that the results of matrix X (rows 3-14 starting from 2nd column) are not updated, if I run it separately for each pair of looped parameters as a check.
Would appreciate any reply.
Thank you,
Aliya
Model10_rer_short.mod (9.78 KB)
search.m (31.4 KB)

As shown above and in numerous posts, you must set the structural parameters you want to vary with

set_param_value('phiinf',X(1,i)); set_param_value('phier',X(2,i));
You cannot simply use

phiinf=X(1,i); phier=X(2,i);
as you did.

Still it doesn’t solve the problem. The matrix X has wrong results. Because the cell (3,2) of X has a number -3.6626e+10, while the correct one should be -2.2986e+11 if a first iteration is that corresponding pair of looped parameters: phiinf=0.5, phier=0.

Your X is

[quote]X =

     0    0.5000    1.0000         0    0.5000    1.0000         0    0.5000    1.0000
     0         0         0    0.5000    0.5000    0.5000    1.0000    1.0000    1.0000
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0
     0         0         0         0         0         0         0         0         0

[/quote]

Using X(1,i) and X(2,i) with i=1 uses phiinf=0, phier=0. Maybe you are confusing rows and columns.

I am not confusing rows and columns. My matrix X is this up to 3rd row after loop is made, I am not showing other rows, sorry for bad formatting. But you see the cell (3,2) which is -36626165419.0826 under phiinf=0.5, phier=0.

0 0.5 1 0 0.5 1 0 0.5 1
0 0 0 0.5 0.5 0.5 1 1 1
-430628478299.734 -36626165419.0826 -5438549262240.73 -1.75290881843188e+15 -916705959054391 -2.86385007585544e+15 -716948367993135 -654920144499515 -2.23270232124789e+15

Now let’s change my looping range as if my first iteration starts from that phiinf=0.5, phier=0. The three rows of matrix X will look like this then, showing that the correct number should be -229862535943.196.

0.5 0.75 1 0.5 0.75 1 0.5 0.75 1
0 0 0 0.5 0.5 0.5 1 1 1
-229862535943.196 -181712327817.607 -5438549262240.73 -3.82907414291894e+15 -1.48502741146982e+15 -2.86385007585544e+15 -1.10183224485801e+15 -829356745047734 -2.23270232124789e+15

You rely on stochastic simulations. Without fixing a seed with

set_dynare_seed('default')
before calling stoch_simul, you will be using different random numbers. The reason is that when calling Dynare, a seed is set. When only calling stoch_simul, this is not the case. You need to do this manually.

I got it now, thank you so much! Such a great opportunity to clarify things on this forum. Success in your further work!

Hi everyone,

Let me continue on this, but in a perfect foresight model. I remember that set_dynare_seed command, as you’ve suggested earlier, helped me to fix my issue in a stochastic model.

Now I am looping over one parameter which affects my exogenous shocks path that I am feeding into a perfect foresight model. I observe that shocks path is replaced properly, yet the results of simulation are not correct after the second iteration of a parameter, if I check just the way I described in my previous post here. Obviously, set_dynare_seed is not a solution as before. What should I control for to deal with basically the same problem, but in a perfect foresight framework?
Would appreciate any helpful reply.

Thank you,
Aliya