Loop over parameters

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Re: Loop over parameters

Postby HouseC » Sun Dec 06, 2015 4:30 am

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.
HouseC
 
Posts: 41
Joined: Fri Apr 19, 2013 3:36 am

Re: Loop over parameters

Postby jpfeifer » Sun Dec 06, 2015 9:52 am

@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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Loop over parameters

Postby jpfeifer » Mon Dec 07, 2015 9:55 am

@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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Loop over parameters

Postby fededipa » Sun Mar 13, 2016 5:46 pm

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
fededipa
 
Posts: 2
Joined: Sun Mar 13, 2016 4:12 pm

Re: Loop over parameters

Postby jpfeifer » Mon Mar 14, 2016 8:14 pm

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Loop over parameters

Postby aeki » Sun Dec 25, 2016 9:25 pm

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!
aeki
 
Posts: 3
Joined: Sun Dec 25, 2016 9:00 pm

Re: Loop over parameters

Postby jpfeifer » Mon Dec 26, 2016 3:18 pm

No, things with
Code: Select all
simul
work differently. As you say, you would need to recompute the initial and terminal values.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Loop over parameters

Postby aeki » Tue Dec 27, 2016 2:53 am

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.
aeki
 
Posts: 3
Joined: Sun Dec 25, 2016 9:00 pm

Re: Loop over parameters

Postby jpfeifer » Tue Dec 27, 2016 6:28 am

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
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Loop over parameters

Postby aeki » Thu Dec 29, 2016 3:35 am

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_')

--------------------------------------------------------------------
aeki
 
Posts: 3
Joined: Sun Dec 25, 2016 9:00 pm

Re: Loop over parameters

Postby jpfeifer » Sun Jan 08, 2017 9:24 pm

Please provide the full files
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Loop over parameters

Postby paidjo » Sun Jan 15, 2017 4:45 pm

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.
Attachments
dynare_loop.m
(846 Bytes) Downloaded 85 times
NK_baseline_steadystate.m
(3.85 KiB) Downloaded 63 times
NK_baseline.mod
(9.84 KiB) Downloaded 68 times
paidjo
 
Posts: 5
Joined: Fri Jul 17, 2015 8:46 pm

Re: Loop over parameters

Postby jpfeifer » Tue Jan 17, 2017 11:11 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Loop over parameters

Postby sidus87 » Tue Feb 21, 2017 10:59 am

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.
Attachments
simulation_changing_para.m
(548 Bytes) Downloaded 75 times
Basu_basic_EZ.mod
(5.91 KiB) Downloaded 65 times
sidus87
 
Posts: 23
Joined: Sat Jun 23, 2012 9:46 pm
Location: London, UK

Re: Loop over parameters

Postby jpfeifer » Thu Feb 23, 2017 5:56 pm

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
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

PreviousNext

Return to Dynare help

Who is online

Users browsing this forum: No registered users and 5 guests