Loops on inputs of the estimation function

Hello everybody;

Is it possible to loop from a .m to give different inputs to the estimation function?

I am using the estimation function for forecasting, and I would like to know if it is possible to loop over the inputs for ‘datafile’ and ‘nobs’ since for each point of the forecast I want to give it a different data set for the forecast.

I welcome suggestions.


Maybe you do not need to code the loop yourself… Did you search for option nobs in the reference manual?



Hi Stepan, thanks for replying, I was reviewing the manual and I understand that it receives integers. My need is to assign that value outside Dynare. I tried it with a macroprocessor and it works for the database but not for the input nobs:

        @#define        model_data     =    "'dataDyn.mat'"
        @#define        sspag               =    "spag"
        estimation(datafile  = @{model_data},
                order        = 1,  mode_compute = 0,
                first_obs    = 13,      
                nobs         = @{sspag},
                forecast     = 8,
                mh_replic    = 0,  mh_nblocks   = 1, smoother,
                posterior_nograph, plot_priors  = 0);  

spag is a value defined in an m-file where the model is run as follows:

        spag = [14:16]
        dynare model.mod nointeractive

but I am not giving it the correct inputs, because it gives me the following problem.

        ERROR: model.mod: line 2982, cols 24-27: syntax error, unexpected NAME, expecting INT_NU

How would it be in this case? Thanks again.


The error message is not surprising… It means you are trying to pass a string value to the nobs option ("spag") which is not allowed. I really don’t understand why you try to use the macro processor here… You can directly pass a range of integers to the nobs option. Except if you want to change the database for each value of nobs (if you need to work with a real time dataset). Is this what you want?

Also, you cannot pass the value of a macro variable as you do when calling dynare. It should be something like:

dynare nameofthemodfile -Dmacrovariable=value

See 3. Running Dynare — Dynare 6.0 documentation


1 Like