# Loop in perfect foresight context

Hi,

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!

No, things with `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.

That depends on how you compute the steady state. In principle, you can just change the first and last entry of

``` oo_.endo_simul```
and then loop over

``` perfect_foresight_solver```

Thank you so much for you reply.

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.

``````-------------- m-file --------------------

%% start iteration

% run dynare
dynare taxpolicy noclearall;

resit_tx = zeros(ntrial,1); % residual

for jj = 1:ntrial

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;
check;

endval;

z_x = 0.95 ;

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

--------------------------------------------------------------------
``````

When we loop over `perfect_foresight_solver`, do we also need to call `perfect_foresight_setup` before calling the solver?
When I looped over parameters, changed the first and last entry of `oo_.endo_simul`, and then called `perfect_foresight_solver`, the solver failed to converge at some iteration. But when I added `perfect_foresight_setup’, it worked fine.
`perfect_foresight_setup` should generally only change the initial and terminal condition in `oo_endo_simul` as well as set up `oo_.exo_simul`. In most applications you only need to call it once, but it’s hard to make general statements.