Loop over parameters

Hi everyone

If I may follow up from this post, I am actually doing the same as kipfilet. But I gotta get the impulse response functions from the newly resolved steady state.

Previously, when I executed the “dynare” command, I simply could use oo_.irfs in my m file. But now, I don’t know where the IRFs are stored after I run the command “[dr_,~,M_,~,oo_] = resol(0,M1_,options1_,oo1_);”.

May I know how I can plot the impulse response functions thereafter?

Thanks.

in that case you actually need to loop over

info = stoch_simul(var_list_);
instead of resol. The irfs will then be stored in their usual place.

5 posts were split to a new topic: Repeating loop with same parameters leads to different results

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

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.

6 posts were split to a new topic: Loop in perfect foresight context

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.
dynare_loop.m (846 Bytes)
NK_baseline_steadystate.m (3.85 KB)
NK_baseline.mod (9.84 KB)

What you do should work, but is extremely inefficient. You should never loop over Dynare, but over the command you need, i.e.

stoch_simul
in your case.

2 posts were split to a new topic: SMM loop stuck at initial values

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?

Another question is, how could I save results of every loop, using the above code?
Thanks a lot!

  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. 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
var_list_ = char();
  1. That depends on what you want to save. To put the results from different runs into a cell array, you could add
results_cell{i}=oo_;

within the loop.

1 Like

3 posts were split to a new topic: Parameter loop at order=3; resol does not work

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

What is the command you want to loop over, stoch_simul?

2 posts were split to a new topic: Loop for human capital model

2 posts were merged into an existing topic: Running Dynare produces different results than a parameter loop

3 posts were split to a new topic: Running Dynare produces different results than a parameter loop

Dear Prof. Jpfeifer,

I am also learning the grid search code now. Based on your posted code, I have two command which I cannot understand.

  1. you set “first_time = 1”, what do you mean by “first_time”?
  2. you set “info = stoch_simul(var_list_)”, what do you mean by “info” and “var_list” respectively?

Maybe my questions are very stupid. I am a new learner, could please help me with it?

Thanks.

  1. This is an indicator to check whether you call the first iteration of the loop. In that case, you need to run Dynare once to initialize everything. Only after that happened, you can call set_param_value to change individual parameters.
  2. This is the function call to stoch_simul that the Dynare preprocessor usually creates when you have a stoch_simul-command in your mod-file. Here, I call the function directly. info is the error code returned by stoch_simul. If it’s not 0, then there was a problem. var_list_ is a character array containing the variable names for which you requested moments etc (the ones listed after the stoch_simul-command in your mod-file). Usually, it is already defined from the first iteration of the loop when you called Dynare as a whole.