# Overloop estimation in .mod takes more than due

**URL:** <https://forum.dynare.org/t/overloop-estimation-in-mod-takes-more-than-due/10689>\
**Category:** DSGE-VAR\
**Created:** [5 September 2017 13:41 UTC](https://forum.dynare.org/t/overloop-estimation-in-mod-takes-more-than-due/10689 "2017-09-05T13:41:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aldo](https://forum.dynare.org/user_avatar/forum.dynare.org/aldo/32/5490_2.png) [@Aldo](https://forum.dynare.org/u/Aldo)\
**Post date:** [5 September 2017 13:41 UTC](https://forum.dynare.org/t/overloop-estimation-in-mod-takes-more-than-due/10689/1 "2017-09-05T13:41:43Z")

</div>

I want to overloop my .mod in dsge\_varlag = [2 3 4]. After estimation command I have (I attach my files)

```
verbatim;
    rho_grid = [2 3 4];    

for i = 1:length(rho_grid)
   		
    options_.first_obs = 5;
    options_.nobs = NaN;            
    options_.dsge_varlag = rho_grid(i);
    oo_recursive_= dynare_estimation(var_list_);
    
    options_.first_obs = 5; % It is necessary repeat this part to call dynare_estimation_init
    options_.nobs = NaN; % It is necessary repeat this part to call dynare_estimation_init
    
    [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_, bayestopt_, bounds] = ...
    dynare_estimation_init(var_list_, [], [], M_, options_, oo_, estim_params_, bayestopt_);
    
  ****
end
end;

```

but when I run this with “dynare mymod” I see it runs four times and it should run just three times. I will repeat this process a lot of times so I need it runs just three times every time.[ls.mod](https://forum.dynare.org/uploads/default/original/2X/3/3fb72ad4866f3f1e8b4dbf4dc1ad3ff8e6f0d7e0.mod) (6.8 KB)  
[newmfile.m](https://forum.dynare.org/uploads/default/original/2X/8/8935a1480b8b54af9ac4a34effd5781f54d8f33d.m) (2.6 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [7 September 2017 08:49 UTC](https://forum.dynare.org/t/overloop-estimation-in-mod-takes-more-than-due/10689/2 "2017-09-07T08:49:50Z")

</div>

In its current version you have the overhead of 1 execution from the initial estimation command in the mod-file before entering the loop. If you just increase the size of the loop, that fixed one additional execution is negligible. If you still want to get rid of it, you need to condition on the first run. See

> [@Loop over parameters](https://forum.dynare.org/t/loop-over-parameters/3335):
>
> Hi, I know that this problem was broached on this forum many times since I found some topics connected with it but I didn’t find any solution for my problem. I want to look at some statistics of variables in the model when some parameters change. The steady state is calculated by hand and included in ‘initval’. For creating the loop over parameters, I used simple syntax like this: rhos = 0.8:0.05:1.05; for i=1:length(rhos); rho = rhos(i); stoch\_simul(order=1); if info; disp('Computation fails…

---

<div class="post-metadata">

**Author:** ![Aldo](https://forum.dynare.org/user_avatar/forum.dynare.org/aldo/32/5490_2.png) [@Aldo](https://forum.dynare.org/u/Aldo)\
**Post date:** [7 September 2017 19:29 UTC](https://forum.dynare.org/t/overloop-estimation-in-mod-takes-more-than-due/10689/3 "2017-09-07T19:29:15Z")

</div>

Thanks dear jpfeifer,

I saw an interesting method to do this in link your shared:

> set\_param\_value(‘rho’,rhos(i));  
> dynare your\_mod\_file\_here noclearall;

Given that I need to set values of dsge\_varlag I am looking for a function similar to **set\_param\_value** that works with dsge\_varlag. Is there some way or recommendation to create this function?

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [8 September 2017 07:38 UTC](https://forum.dynare.org/t/overloop-estimation-in-mod-takes-more-than-due/10689/4 "2017-09-08T07:38:06Z")

</div>

1. The snippet you posted is not a good idea, because you would run the Dynare preprocessor in every iteration. Dynare should only be run in the first iteration. Within the mod-file, you simply hardcode the first value of the parameter
2. `dsge_varlag` is not a parameter. Therefore no similar function is available. Changing it requires quite intensive recomputations like the empirical moments. The way you programmed this was right.

---

<div class="post-metadata">

**Author:** ![Aldo](https://forum.dynare.org/user_avatar/forum.dynare.org/aldo/32/5490_2.png) [@Aldo](https://forum.dynare.org/u/Aldo)\
**Post date:** [8 September 2017 14:18 UTC](https://forum.dynare.org/t/overloop-estimation-in-mod-takes-more-than-due/10689/5 "2017-09-08T14:18:41Z")

</div>

> [@jpfeifer](#):
>
> dsge\_varlag is not a parameter. Therefore no similar function is available. Changing it requires quite intensive recomputations like the empirical moments. The way you programmed this was right.

Thanks dear jpfeifer.

Cheers
