Page 1 of 2

help looping over two parameters

PostPosted: Sun Apr 19, 2015 4:19 am
by hakeru7
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

Re: help looping over two parameters

PostPosted: Sun Apr 19, 2015 9:03 am
by jpfeifer
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" https://sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf.

Re: help looping over two parameters

PostPosted: Sun Apr 19, 2015 5:13 pm
by hakeru7
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?

Re: help looping over two parameters

PostPosted: Sun Apr 19, 2015 5:26 pm
by hakeru7
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....

Re: help looping over two parameters

PostPosted: Mon Apr 20, 2015 9:25 pm
by jpfeifer
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.
Code: Select all
parameters eeta Y_SS

and
Code: Select all
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.

Re: help looping over two parameters

PostPosted: Tue Apr 21, 2015 3:39 pm
by hakeru7
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.

Re: help looping over two parameters

PostPosted: Tue Apr 21, 2015 4:43 pm
by jpfeifer
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.

Re: help looping over two parameters

PostPosted: Tue Apr 21, 2015 5:19 pm
by hakeru7
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"?

Re: help looping over two parameters

PostPosted: Tue Apr 21, 2015 5:30 pm
by jpfeifer
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.

Re: help looping over two parameters

PostPosted: Tue Apr 21, 2015 5:56 pm
by hakeru7
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.

Re: help looping over two parameters

PostPosted: Tue Apr 21, 2015 7:52 pm
by jpfeifer
Sorry, my mistake. I only read the heading
// model in logs

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

Re: help looping over two parameters

PostPosted: Tue Apr 21, 2015 9:10 pm
by hakeru7
Sorry for the confusion. My file could have been neater...

Thanks so much for the all your comments and suggestions!

Re: help looping over two parameters

PostPosted: Thu Apr 23, 2015 9:00 pm
by pito
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

Re: help looping over two parameters

PostPosted: Fri Apr 24, 2015 7:48 am
by jpfeifer
As shown above and in numerous posts, you must set the structural parameters you want to vary with
Code: Select all
set_param_value('phiinf',X(1,i));
set_param_value('phier',X(2,i));

You cannot simply use
Code: Select all
phiinf=X(1,i);
phier=X(2,i);

as you did.

Re: help looping over two parameters

PostPosted: Fri Apr 24, 2015 8:15 am
by pito
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.