Macroprocessor option, conditional directive controlled externally

Dear professor,I wonder if there is a way to pass more than 2 value externally. Using the example in macroprocessor.pdf

Example: alternative monetary policy rules
@#define linear_mon_pol = false // or 0

model;
@#if linear_mon_pol
i = w*i(-1) + (1-w)i_ss + w2(pie-piestar);
@#else
i = i(-1)^w * i_ss^(1-w) * (pie/piestar)^w2;
@#endif

end;

Now I want to change @#define linear_mon_pol = false //or 0 into
@#define rule1=0 or 1
@#define rule2=0 or 1
@#define rule3=0 or 1
and each value is assigned externally. In this way, 8 combinations can be controlled externally. But set_param_value('rule1_value',rule1_value); and then @#define rule1=rule1_value doesn’t work. Dynare tells me ‘Unknown variable: rule1_value’.
Is there any way to achieve this goal?

What exactly is the full error message? You can define 8 values. But what do you mean with

?

Hi professor. I mean if I @#define rule1=0, dynare works well.
But I want to trigger the .mod file in loops, and use a parameter to select rules externally. My idea is to use a new parameter named rule1_value, set rule1_value=0 externally, use command set_param_value('rule1_value',rule1_value) to pass value, and then @#define rule1=rule1_value.
But it seems that the @#define command can only distinguish a number (i.e. 0), but not a variable (i.e. rule1_value). I wonder if this is because the dynare handles the macroprocessor commands before set_param_value command. If this is the reason, how can I fix the problem?

Have a look at DSGE_mod/run_welfare_comparison_efficient_steady_state.m at master · JohannesPfeifer/DSGE_mod · GitHub
how we passed switches the -D option at the command line. That allows looping.

1 Like

Oh, in an earlier topic I noticed this method, but I thought it could support only 1 value. But this new example seems really adorable! Thank you, professor.