Loop in a mod file

Dear all,

I want to estimate a bvar, using the bvar a la sims toolkit over a given sample and i want to reestimate it every quarter, as Smets and Wouters do in their aer (2007) paper. As an example in my do file, i try something like :

for i = 1:100
bvar_density(datafile = mydata, first_obs = myfirstobs, bvar_prior*, presample, nobs = 44 + i-1 (for instance))

I get an error message since dynare does not expect the “+” and the “-” in the options. Is there any way to solve the problem?

I would greatly appreciate your help.


For only 100 iterations, you can use the new macro-language which was introduced recently in Dynare.

Install Dynare 4.0.0, and replace your code by the following:

@#for i in 1:100
bvar_density(datafile = mydata, first_obs = myfirstobs, …, presample, nobs = @{44+i-1})

For more information on the macro-language, have a look at the file “macroprocessor.pdf” distributed in the archive for Dynare 4.0.0, or go to:




NB: * new url

Thanks Sebastien for the reply and for this new macroprocessor. But I woul like to add just a little correction : “@#end” does’nt work but “@endfor” does.

I have appreciated your help.