hello

i need apply some different value for one of parameters , so i write a loop in dynare mod-file like example of dynarewiki(*http://www.dynare.org/DynareWiki/HowtoLoops*)

but after i run model i get this error

Configuring Dynare …

[mex] Generalized QZ.

[mex] Sylvester equation solution.

[mex] Kronecker products.

[mex] Sparse kronecker products.

[mex] Bytecode evaluation.

[mex] k-order perturbation solver.

[mex] k-order solution simulation.

Starting Dynare (version 4.1.2).

Starting preprocessing of the model file …

Found 24 equation(s).

Evaluating expressions…done

Computing static model derivatives:

- order 1

Computing dynamic model derivatives:
- order 1

Processing outputs …done

Preprocessing completed.

Starting MATLAB/Octave computing.

??? Attempted to access rhoAs(0); index must be a positive integer or logical.

Error in ==> finalmodel6q at 271

M_.params( 30 ) = rhoAs(oo_.steady_state(4));

Error in ==> dynare at 132

evalin(‘base’,fname) ;

I attach my mod file

I don,t know what is this error?

please help me

Thanks

finalmodel6q.mod (2.15 KB)

Nazanin,

I have just experienced the same problem using the same webpage as my template. It took me a little bit of time to work out what to do, but I have managed to find a way of doing what I want to do.

I used the Dynare Reference Manual (which you can get online but which is also downloaded when you download the Dynare software) and page 58 (page 62 once you include all the contents pages etc.) where we are shown how to write the loop using a ‘macro-processor’ loop.

Now, I must say I am very new to both Dynare and Matlab, and therefore I don’t really know why this should work, but it does.

So with reference to your specific example, try typing:

```
rhoAs = 0.2:0.05:1.05;
@#for i in 1 : 18 \\I havn't managed to get it to work with the 'length' function - I don't know why
rhoA = rhoAs (@{i});
stoch_simul(order=1);
@#endfor
```

I have attached my copy of your .mod file which I have just got to work. Hopefully this should be helpful, but let me know if something goes wrong.

Richard.

Nazanin’s example doesn’t work because ‘i’ is both declared as a variable in VAR and used as the Matlab loop index. This confuses Dynare.

r.mcmanus’ example uses Dynare macrolanguage loop rather than a Matlab loop. The syntax is different and there is no length() function in Dynare macrolanguage.

Be careful not to confuse Matlab loops and Dynare macrolanguage loops. Both can be used and have their advantages and shortcomings depending on the context.

Matlab loops are executed at computation time, while Dynare macrolanguage loops repeat statements in a intermediary *.mod file.

Best

Michel