# Parameter loops

**URL:** <https://forum.dynare.org/t/parameter-loops/19555>\
**Category:** Stochastic simulations\
**Created:** [3 January 2022 09:14 UTC](https://forum.dynare.org/t/parameter-loops/19555 "2022-01-03T09:14:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![turtleman](https://forum.dynare.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@turtleman](https://forum.dynare.org/u/turtleman)\
**Post date:** [3 January 2022 09:14 UTC](https://forum.dynare.org/t/parameter-loops/19555/1 "2022-01-03T09:14:27Z")

</div>

Hello,

I have a basic DSGE model and am trying to find the value of a parameter (b) that solves a particular equation (f(X)=0) where X is a vector of covariances.

More specifically, using Dynare I can solve the DSGE model conditional on the value of parameter b and derive covariances of endogenous variables which I denote as a vector, X(b). This allows me to compute the equation f(X(b)) and see if it is close to 0.

I would like to do this for many values of b and find the value of b that makes f(X(b)) closest to 0, which I think requires me to do a loop.

Is there a simple way to implement loops in Dynare? I have looked at some other forum posts, but I am still unclear as to how to implement loops.

Thank you.

Best,  
John

---

<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:** [4 January 2022 08:38 UTC](https://forum.dynare.org/t/parameter-loops/19555/2 "2022-01-04T08:38:21Z")

</div>

The closest would be

> [@Optimal policy parameters in a non-linear model](https://forum.dynare.org/t/optimal-policy-parameters-in-a-non-linear-model/11772/2):
>
> You need to write an objective function and maximize it. The code for the maximization part to be added to the mod-file would be x\_start=[0.01, 0.01, 0.01, 0.01]'; %define parameters to be optimized and their upper and lower bound x\_opt\_name={'alpha\_le',0,Inf 'alpha\_qky',0,Inf 'alpha\_ve',0,Inf 'alpha\_cg',0,Inf }; options\_.nofunctions=1; options\_.nograph=1; options\_.verbosity=0; %set noprint option to suppress error messages within optimizer opti…

or

> <https://github.com/JohannesPfeifer/DSGE_mod/tree/master/RBC_IRF_matching>
>
> //github.com/JohannesPfeifer/DSGE\_mod/tree/master/RBC\_IRF\_matching
