# Dynare loop for - help

**URL:** <https://forum.dynare.org/t/dynare-loop-for-help/4544>\
**Category:** Dynare help (legacy posts)\
**Created:** [6 March 2015 09:11 UTC](https://forum.dynare.org/t/dynare-loop-for-help/4544 "2015-03-06T09:11:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![skimeur](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/ed8c4c/32.png) [@skimeur](https://forum.dynare.org/u/skimeur)\
**Post date:** [6 March 2015 09:11 UTC](https://forum.dynare.org/t/dynare-loop-for-help/4544/1 "2015-03-06T09:11:11Z")

</div>

Hello,

I am trying to make a simple loop over monetary policy parameters.

I replicated the Gertler & Karadi model.

Then I create a main Matlab file of the type:

param1 = 0.1;  
param2 = 0.972;  
for ii = 0.5:0.05:0.6  
param3 = ii;  
save (‘my\_param.mat’, ‘param1’, ‘param2’, ‘param3’,);  
clear all;  
dynare my\_file.mod noclearall;  
end

Then in the .mod file, I declare the parameters and just after I add:  
load my\_param.mat;  
before the command  
model;

It doesn’t even computethe steady state, what is wrong with my basic code?  
How to do a basic for loop with Dynare?

If I make it work, how do I store all the results (parameters value and welfare calculated) to be able to compare them latter?

---

<div class="post-metadata">

**Author:** ![joff](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/8797f3/32.png) [@joff](https://forum.dynare.org/u/joff)\
**Post date:** [6 March 2015 09:52 UTC](https://forum.dynare.org/t/dynare-loop-for-help/4544/2 "2015-03-06T09:52:42Z")

</div>

These should be helpfull:

> [@Loop over parameters](https://forum.dynare.org/t/loop-over-parameters/3335/1):
>
> 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…

> [@Simulated moments](https://forum.dynare.org/t/simulated-moments/670/1):
>
> When the moments are calculated from simulations, they are calculated from a single simulation (of size=periods), correct? Is there quick way to take the average of multiple simulations to get the moments? Thanks.
