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 zhanshuo » Thu Apr 06, 2017 4:10 pm

HI, everyone, I wonder if there is now a more convenient way to loop over parameters using dynare 4.5(unstable).
If there is , I am so honored if you let me know.
and I am learning about the code above, and have some questions?
first_time = 1;
for i=1:length(rhos)
if first_time
set_param_value('rho',rhos(i));
dynare your_mod_file_here noclearall;
first_time = 0;
else
set_param_value('rho',rhos(i));
info = stoch_simul(var_list_);
if info;
disp(['Computation fails for rho = ' num2str(rho)]);
end;
end
end

1, why should "info=1" be judged? so when info=1, the model is wrong?
2, " info = stoch_simul(var_list_);" Since the "var_list_" is sometime empty,how should I do?
zhanshuo
 
Posts: 44
Joined: Fri Nov 25, 2016 7:59 am

Re: Loop over parameters

Postby zhanshuo » Thu Apr 06, 2017 4:30 pm

Another question is, how could I save results of every loop, using the above code?
Thanks a lot!
zhanshuo
 
Posts: 44
Joined: Fri Nov 25, 2016 7:59 am

Re: Loop over parameters

Postby jpfeifer » Thu Apr 06, 2017 5:19 pm

1. Yes, that is still the proper way to do it.
2. info is the error code from stoch_simul. If info is not 0, the model could not be solved (for various possible reasons). It's not necessarily the case that the model is wrong, but rather that the particular parameter draw in the loop is problematic.
3.
Code: Select all
var_list_
will typically be created by Dynare in the first run and you do not need to set it in this case. If in your application you need to set it manually, you should be able to set it to an empty character array
Code: Select all
var_list_ = char();

4. That depends on what you want to save. To put the results from different runs into a cell array, you could add
Code: Select all
results_cell{i}=oo_;

within the loop.
------------
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 Zen » Mon May 08, 2017 12:10 pm

Hi everyone

If I'm not mistaken, resol only works for a first- and second-order approximation of the model, but not for a third. Is there another function which does the same as resol, but also works with a third-order approximation?

Many thanks
Zen
 
Posts: 2
Joined: Tue Sep 06, 2016 3:32 pm

Re: Loop over parameters

Postby jpfeifer » Mon May 08, 2017 12:22 pm

It also works for third order. But you have to make sure
Code: Select all
options_.qz_criterium

Has been set
------------
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 Zen » Mon May 08, 2017 2:39 pm

Thanks for your quick answer. I had also to set manually option_.k_order_solver = 1 in order to get any results.
Zen
 
Posts: 2
Joined: Tue Sep 06, 2016 3:32 pm

Re: Loop over parameters

Postby PPilo » Thu May 11, 2017 1:06 pm

Hello

I am simulating a very simple RBC model and would like to let the constant tax rate vary. I can do this manually by just resetting the paramter every time I run the code. However, is it possible to perform this automatically? Say, I want the tax rate to increase by 0.1 every time (from 0 to 0.5).
Can I do this in my mod-file or do I have to write a m-file?

Thanks a lot,
PPilo
PPilo
 
Posts: 1
Joined: Thu May 11, 2017 1:01 pm

Re: Loop over parameters

Postby jpfeifer » Sun May 14, 2017 10:13 am

What is the command you want to loop over, stoch_simul?
------------
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

Previous

Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 11 guests