Hi,
In a multi-country model, I’ve got some countries with a fixed exchange rate and others with a floating exchange rate. Suppose I store this information in the numerical vector fixed = [0 0 1 1 1] in matlab, where countries 3 to 5 have a fixed exchange rate. I then call dynare from matlab using the ‘dynare …mod’ command.
In the .mod file I loop through the various countries and for the equations describing the monetary policy rule, I think I have to put in an if loop along the following lines
@#for i in countries
@#if fixed@{i}==1
‘code describing monetary policy with fixed exchange rate’
@#else
‘code describing monetary policy with floating exchange rate’
@#endif
@#endfor
Ideally, I’d like to input this information on the command line when calling dynare
dynare …mod -Dfixed=fixed
Is there a way to implement this with the macro language? Thanks!
I tried something along the following lines, but it indicates a syntax error:
In the main file, I’ve got
ctys = ‘[“H1”,“H2”,“H3”]’;
eval([‘dynare model_ex -Dfixed=[1,1,0] -Dleader=[1,0,0] -Dcountries=’,ctys])
and then in the my_model.mod file, I’ve got
@#define N = length(countries)
…
model;
@#for nb in 1:N
@define i = countries(@{nb});
[name=‘1. Marginal utility of consumption’]
MU@{i} = C@{i}^(-1/sigma);
…
[name=‘10 Monetary policy’]
@#if fixed(@{nb})==1
‘code describing monetary policy with fixed exchange rate’
@#else
‘code describing monetary policy with floating exchange rate’
@#endif
@#endfor
But I get an error saying:
syntax error, unexpected TEXT, expecting COMMA or RPAREN
model_ex.mod (5.5 KB)
main_ex.m (116 Bytes)
@sebastien Do you know the answer?
There are many syntactical errors in the macro-language code of this .mod file.
— At some places you wrote @define
instead of @#define
— When selecting the element of an array, you have to use brackets [ ]
instead of parentheses
— You should not use the @{}
syntax within a macro-statement.
For example, the line @#if fixed(@{nb}) == 1
should rather be written @#if fixed[nb] == 1
(brackets + no @{}
). There are many other similar errors in the file.