Use a function to determine initial and final values of model


I’m working on a model to solve for optimal transition path in perfect foresight setting.
I have some difficulties to find the right parameters to make my model converge.
So, I wanted to do a loop on some parameters inside the mod file.
However, the initial and final values of my steady states exogenous variables are affected by the changing parameters.
Is it possible to call a function that determines this new initial and final values ?
I’ve seen the NK_baseline example, but it is for parameters and not for initval and endval.

Thank you very much,
Best regards,

Are your initial and terminal values steady states? If yes, calling steady after initval and endval should do the trick. Alternatively, manually set the entries created by perfect_foresight_setup when looping.

Thank you for your answer! Yes, they are steady states. But I’m using a calibration file in parallel to set the value of one constant exogenous variable depending on the choice of my parameters. To be more precise, I’m setting my exchange rate to 1 at the initial value which helps me determine exogenous foreign demand for a good, which is constant in the transition. I find my final value of the exchange rate fixing the value of foreign demand. For now, I need to run this calibration file each time I’m changing the parameters to solve my steady state . But, it is not possible with a loop, so I’ve built a fsolve function, but I’m not sure I can use it in the mod file. What do you mean by manually setting the entries by perfect_foresight_setup ?

Could you provide me with the files that do one iteration of the simulation?

Dear Johannes

I wonder how to loop over different values of permanent shocks using this method. I tried assigning relevant oo_.exo_simul with a non-zero sequence of shocks throughout the entire simulation periods. However, perfect foresight solver does not update my endval (the new steady state) because those shocks are essentially transitory. Is there a way in which I can modify my endval block directly when using perfect_foresight_solver_core ?

Hope to hear from you soon!

Can you provide the codes?

I modified it from the code you provided in one of the forums:
My simulation period is 750. I loop over different values of e_f (shock).

numit =0;
for jj = 1:length(e_f_vec)
    numit = numit+1;
    sequence_of_policy = [0; e_f_vec(jj)*ones(751,1)];
    oo_.exo_simul(:,9) =  sequence_of_policy;
    oo_ = perfect_foresight_solver_core(M_,options_,oo_);
    if oo_.deterministic_simulation.status
       welfare_c(numit) = oo_.endo_simul(pos_welfare_cons_o,390);

You still need to set the terminal condition. If you can compute that one, you can directly set the last column of oo_.endo_simul.

Still, this wouldn’t change my final steady state, right?

Dynare gives me different transitional dynamics for when I use steady; after the endval block vs when I don’t use it even if I assigned all variables in the endval block exactly their new steady state values. Without steady;, oo_.endo_simul potrays transitional paths of all enognous variables towards the endval on the condition that the economy will return to its initial state. Clearly, this should not be the case because I am working with permanent shocks which brings about new economic outcomes. So, I wonder if there’s a way the change the (final) steady state, and not just the terminal condition.

In short, is there any way to loop over different sets of endval; ?

steady after endval compute the steady state conditional on the specified exogenous variables. Thus, what you describe indicates that the values you provide are not really a steady state.

Note that the content of endval or the steady state computed by steady (if present) are written into the last column of oo_.endo_simul. That makes looping over them straightforward.

I see. Thank you.