Page 3 of 4

Re: Loop over parameters

PostPosted: Sun Dec 06, 2015 4:30 am
by HouseC
monsoon wrote:Just clarifying a doubt with reference to the above topic. Is looping important when we deal with endogenous collateral constraints?

I guess what's discussed here is on changing the parameters and get moments by redoing simulations. The importance of loop is not related with model setup, which is how to deal with constraints.

Re: Loop over parameters

PostPosted: Sun Dec 06, 2015 9:52 am
by jpfeifer
@HouseC I would need to see the mod-file you are calling.
@monsoon Looping is somewhat related to how to deal with occasionally binding constraints, because solving this type of model sometimes requires iterating over different parameters/models (see Guerierri/Iacoviello's Occbin). But there is no general fundamental relation between loops and constraints.

Re: Loop over parameters

PostPosted: Mon Dec 07, 2015 9:55 am
by jpfeifer
@HouseC Within your mod-file you use the stochastic simulations that rely on random numbers. Dynare, when called, uses
Code: Select all
set_dynare_seed('default');

to set the seed of the random number generator. Thus, before you call
Code: Select all
info=stoch_simul(var_list_);

you should have
Code: Select all
set_dynare_seed('default');

to fix the seed, if this is desired.

Re: Loop over parameters

PostPosted: Sun Mar 13, 2016 5:46 pm
by fededipa
Hi there,

The parameters I want to loop over will change the steady state. Is there an efficient way to do this? Essentially I need to find a solution to the steady state each time I loop over the values of one parameter?

Best,

Federico

Re: Loop over parameters

PostPosted: Mon Mar 14, 2016 8:14 pm
by jpfeifer
stoch_simul (and resol) will compute the steady state before computing the decision rules at this point, so you do not need to worry about this.

Re: Loop over parameters

PostPosted: Sun Dec 25, 2016 9:25 pm
by aeki
Hi,

jpfeifer wrote:stoch_simul (and resol) will compute the steady state before computing the decision rules at this point, so you do not need to worry about this.


Does this answer apply to "simul", too? I am trying to estimate the parameters by matching the deterministic path (rather than the IRF). In each iteration of SMM, I change the parameter value by "set_param_value" and run "simul" to obtain the deterministic transition path. I however wonder whether I also have to recompute and change "initval" and "endval" (i.e., the old and new steady state) in each iteration, because those values must be changed when I change the parameters.

Thanks!

Re: Loop over parameters

PostPosted: Mon Dec 26, 2016 3:18 pm
by jpfeifer
No, things with
Code: Select all
simul
work differently. As you say, you would need to recompute the initial and terminal values.

Re: Loop over parameters

PostPosted: Tue Dec 27, 2016 2:53 am
by aeki
Thank you for your prompt reply, jpfeifer!

jpfeifer wrote:No, things with
Code: Select all
simul
work differently. As you say, you would need to recompute the initial and terminal values.


Oh, Really... Do we have a good way to reset "initval" and "endval" before running "simul" in each loop? I mean, how can I reset these values in each iteration as I change the parameter values by "set_param_value"? Thanks.

Re: Loop over parameters

PostPosted: Tue Dec 27, 2016 6:28 am
by jpfeifer
That depends on how you compute the steady state. In principle, you can just change the first and last entry of
Code: Select all
oo_.endo_simul

and then loop over
Code: Select all
perfect_foresight_solver

Re: Loop over parameters

PostPosted: Thu Dec 29, 2016 3:35 am
by aeki
Thank you so much for you reply.

jpfeifer wrote:That depends on how you compute the steady state. In principle, you can just change the first and last entry of
Code: Select all
oo_.endo_simul

and then loop over
Code: Select all
perfect_foresight_solver


As you point out, I think it depends on how to compute the steady state. My code is like the following. I should:

(1) loop over "perfect_foresight_solver" rather than "simul", and
(2) compute the steady-state for the initial and end point, and replace the initial and end value of "oo_.endo_simul" by these new steady state values, before running "perfect_foresight_solver",

I am sorry to ask such a primitive question, but how do I compute the steady-state for both the initial point and the end point outside the mod-file? If I use "steady" after setting a new parameter value, it computes the steady state only at the end point.

Thank you in advance.

-------------- m-file --------------------

%% start iteration

% run dynare
dynare taxpolicy noclearall;

resit_tx = zeros(ntrial,1); % residual

for jj = 1:ntrial

load level0workspace

set_param_value('tau_rate',params_tr(jj));

simul;

resit_tx(jj) ...
= (y_data(mt,1)-oo_.endo_simul(1,mt)')'/(y_data_sd^2)...
*(y_data(mt,1)-oo_.endo_simul(1,mt)') ;

end

----------------------------------

---------- mod-file: taxpolicy.mod--------------
...

<model part>

...

initval;

z_x = 1.0 ;

end;
steady;
check;

endval;

z_x = 0.95 ;

end;
steady;
check;

shocks;
var z_x ;
periods 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ;
values 1 0.997438621 0.994883803 0.992335529 0.989793782 0.987258545 0.984729802 0.982207536 0.97969173 0.977182369 0.974679434 0.972182911 0.969692783 0.967209032 0.964731643 0.9622606 0.959795886 0.957337486 0.954885382 0.952439558 0.95;
end;

simul(periods=1000);
evalin('base','save level0workspace oo_ M_ options_')

--------------------------------------------------------------------

Re: Loop over parameters

PostPosted: Sun Jan 08, 2017 9:24 pm
by jpfeifer
Please provide the full files

Re: Loop over parameters

PostPosted: Sun Jan 15, 2017 4:45 pm
by paidjo
Hi jpfeifer,

I am trying to loop over 3 parameters. Say, I want to get the simulated variance of output under different combinations of parameters. Just to illustrate, I used the NK_baseline.mod you wrote. In my code (dynare_loop.m), I looped over the Taylor rule parameters (gammmaR, gammmay, and gammmaPI) then stored the simulated variance in a mat file. For what I want to get, is my code correct? Thank you.

Re: Loop over parameters

PostPosted: Tue Jan 17, 2017 11:11 am
by jpfeifer
What you do should work, but is extremely inefficient. You should never loop over Dynare, but over the command you need, i.e.
Code: Select all
stoch_simul

in your case.

Re: Loop over parameters

PostPosted: Tue Feb 21, 2017 10:59 am
by sidus87
Dear All,

I have a related question to the previous ones. I would like to estimate my model by SMM and I looked at Johannes's replication codes and tried to re-write it myself. Nevertheless I got a problem, which you can help me with. As I was always getting that the initial value was the local minimum, I started digging into what could cause the issue, so i just try to simulate the model changing the parameters and see what moment it gives for a specific variable (say "r").

I do the following:
1)run mod file.
2)change param value with set_param_value('paraname',paravalue);
3)[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); %run model solution in Dynare
4) simulate with simult_
5) get the the simulated moment of interest



what i get is the following: a) even using the same parameter value (beta=0.994) as in the mod. file, the moment (in my case the mean of r) i get from 5) is different to that printed by dynare, when i run the mod in 1).
b) regardless of the parameter value, the moment doesn't change, moreover if I set the parameter equal to that in the mod.

I'm attaching the mod file and the m. file, so maybe it's clearer and easier to spot the issue. Thank you very much in advance for your help.

Re: Loop over parameters

PostPosted: Thu Feb 23, 2017 5:56 pm
by jpfeifer
Your mod-file does not correctly handle parameter dependence. That way, beta is changed, but beta does not enter the mod-file and all parameters depending on beta are not changed. Either use model-local variables (# operator) or a steady state file