Total number of periods given by variable

Hi, this is a rather simple syntax question, but if solved can save me a lot of time and make my work much less cumbersome.

I have deterministic OLG models and need to define the number of periods for shocks and for simulation in a generic fashion. That is, instead of writing explicitly “periods 1:10” in the shocks block, for example, I would like to be able to write something like “periods 1:T”, where T is a variable predefined by me. The same goes for “simul (periods = T2)”, where T2 would also be a variable predefined by me.

I tried to solve this problem by using the macroprocessor, but to no avail. The farthest I got was to write:

@#define shocks_length = "1:10"
periods @{shocks_length}

But this does not help at all. The “10” is still explicitly written there and I cannot change it easily whenever I need. I run many different dynare models in my routine (closed economies and open economies) and all of them must have the same number of periods T and T2 at each run (and I want to vary these easily).

Thank you so much for your help.

Best,
Felipe

I am not sure I understand. Usually, you would usually define

@#define T = 10
@#define T2=100

and then later

periods 1:@{T}
simul (periods = @{T2})

Alternatively, instead of defining T and T2 in the mod-file, you could pass them at the command line via the -D switch:

dynare mymodel -DT=10 - DT2=100

Thank you @jpfeifer. It solved my problem.
I was not aware of this -D switch. It will be of great help.

Best,
Felipe

Hi @jpfeifer.
Sorry to ask again, but I now have another question. I want to use the @{} structure to vary easily the number of countries in my n-country open-economy model. So I will use the -D switch to input the number of countries when I call dynare in my Matlab routine. For example:

eval(['dynare mymodel -Dncountries=' int2str(n_countries)])

Where n_countries is an input in my Matlab routine.
Then, in the dynare file, I would write:

@#define countries = 1:@{ncountries}
@#for co in countries
…and so on.

However, apparently the macroprocessor does not accept this syntax of a @{} inside a @#define directive. I tried many ways to get around this, but was not successful.

Can you help me once again?

Thank you.

Best,
Felipe

That is an unfortunate limitation. See https://github.com/DynareTeam/dynare/issues/1578