# Looping over parameter values and time horizons

**URL:** <https://forum.dynare.org/t/looping-over-parameter-values-and-time-horizons/22063>\
**Category:** Stochastic simulations\
**Created:** [10 March 2023 09:17 UTC](https://forum.dynare.org/t/looping-over-parameter-values-and-time-horizons/22063 "2023-03-10T09:17:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![VS19](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@VS19](https://forum.dynare.org/u/VS19)\
**Post date:** [10 March 2023 09:17 UTC](https://forum.dynare.org/t/looping-over-parameter-values-and-time-horizons/22063/1 "2023-03-10T09:17:15Z")

</div>

Hi Everyone,

I am trying to loop over a (calibrated) parameter in the simulation (stoch\_simul) of my model. I want to see impact on variables of interest by varying this parameter and over a few time horizons (for example, on impact, in the medium term and in the (very) long run, that is, t = 0, t = 40, t = 10000). So I want to run a loop over this parameter over 3 time horizons. I need to save and tabulate the results. Can you please advise how to do this? I looked at previous questions on [looping over parameters](https://forum.dynare.org/t/loop-over-parameters/3335/2) but could not figure out how to do this over several time horizons and then save the results. Probably a second loop for different time horizons has to be added. Will appreciate any suggestion.

---

<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:** [10 March 2023 13:08 UTC](https://forum.dynare.org/t/looping-over-parameter-values-and-time-horizons/22063/2 "2023-03-10T13:08:18Z")

</div>

Which object are you trying to extract? IRFs? If yes, then simply set the maximum horizon, loop over the parameter and extract the three entries you are interested in.

---

<div class="post-metadata">

**Author:** ![VS19](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@VS19](https://forum.dynare.org/u/VS19)\
**Post date:** [10 March 2023 13:37 UTC](https://forum.dynare.org/t/looping-over-parameter-values-and-time-horizons/22063/3 "2023-03-10T13:37:16Z")

</div>

Thank you so much, @jpfeifer. Yes, I am trying to calculate IRFs. Can I kindly ask what is wrong with my parameter loop? I created a `.m` file for loop, as suggested by you on this forum and placed it in the same folder as my `.mod` file. I tried to run the `.m` file but it does not do anything. I must be making a mistake. Can you please advise? I attach the relevant files.  
[loop2.m](https://forum.dynare.org/uploads/short-url/aKJmzND1ysFq7L5R2Kuv8eQpAx1.m) (425 Bytes)  
[testmodel.mod](https://forum.dynare.org/uploads/short-url/4eophSQDaMZ362NszYgFnO22WBE.mod) (5.8 KB)  
[findsteady\_RL.m](https://forum.dynare.org/uploads/short-url/3IQgp0jUp6GYTnBIbERr5XVn90I.m) (160 Bytes)

---

<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:** [10 March 2023 13:45 UTC](https://forum.dynare.org/t/looping-over-parameter-values-and-time-horizons/22063/4 "2023-03-10T13:45:47Z")

</div>

You are not handling parameter dependence correctly.
