loop error

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

loop error

Postby nazanin » Wed Jun 15, 2011 7:22 am

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
Attachments
finalmodel6q.mod
(2.15 KiB) Downloaded 364 times
nazanin
 
Posts: 8
Joined: Sun Feb 27, 2011 10:32 am

Re: loop error

Postby r.mcmanus » Fri Aug 12, 2011 1:01 pm

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:

Code: Select all
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.
r.mcmanus
 
Posts: 2
Joined: Fri Aug 12, 2011 12:34 pm

Re: loop error

Postby MichelJuillard » Fri Aug 12, 2011 8:33 pm

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
MichelJuillard
 
Posts: 680
Joined: Thu Nov 18, 2004 10:51 am


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 11 guests