Changing Dynare order outside the .mod file

Hi,

I need to do a grid search for a range of parameters, for which I use

set_param_value('param', value(i));
stoch_simul(var_list_);

but in each iteration, I need to get the derivatives both for the first and third order expansions. That is, for each parameter, I need to get two sets of derivatives (for 1st and 3rd order). Could you please let me know if/how I can do this.
Note: I have already tried to just change the order using options_.order = 3;, but I wasn’t successful.

Many thanks in advance,
Soroush

What do you mean? Which error do you get? You need to run Dynare at order 3 first. That is, you use

in the mod-file and call it with

at the beginning of your code. This will create all required files. Then you can switch between first and third order by setting

Thank you very much jpfeifer, it works now. As you correctly guessed, I was using the wrong order. Just a quick follow up question, and please don’t bother if there is not a good answer for that. When I tried the following piece of code:

dynare afr0test
f_11_3 = [oo_.dr.ghx oo_.dr.ghu];

stoch_simul(var_list_);
f_11_test3 = [oo_.dr.ghx oo_.dr.ghu];

sum(vec(f_11_test3 -f_11_3)) %showing if the first order derivatives have changed

to see if running the same file from outside (i.e. using the stoch_simul) has changed the first-order derivatives, I got 2.14e-6. Admittedly, I have a lot of variables in the models (66 variables), which means each derivative is just changed a tiny bit, but do you know why there is a change in the first place?

Thanks again.

Hard to tell without the model. Do you use a steady state file?
In any case, a better test is max(max(abs(f_11_test3 -f_11_3)))

When calculating the stochastic steady state as proposed by Johannes in another part of this forum (thanks Johannes!) I came across something which might be a bug? (or I’m overlooking something). I’m also using my .mod file for other stuff, therefore, I specifiy the approximation order in a parameter file. This worked fine up to order 2, however, no I’m encountrering the following error message:

The derivatives were not computed for the required order. Make sure that you used the right order option inside the stoch_simul command

I used the following code in my dynare file:


param_order=3;

options_.order=param_order;
options_.nograph=1;
options_.noprint=1;

if param_order == 1
options_.irf=40;
end;

if param_order == 2
options_.irf=0;
options_.nodisplay=1;
end;

if param_order == 3
options_.irf=0;
options_.k_order_solver=1;
options_.pruning=1;
end;

stoch_simul;


Obviously I can get around this problem by writing


if param_order == 3
stoch_simul(order=3);
else
stoch_simul;
end


instead of just stoch_simul, but still, it seems inconsitent, therefore, I wanted to point it out.

The reason is that the third order derivatives are only computed by the preprocessor if order=3 is detected inside of the mod-file.