If statements within block model

Good morning I am a total newbie with Dynare, and I am trying to buid a simple model of debt dynamics.

I defined the equations in the model block, and one of these is the government reaction function, that determines spending according to its debt target.
I’d like to have an if statement. Something like:

if b<=60,
dcur = delta10.05(b0-bstar);
invg = chi0*dsp;

This is what I’d do in a matlab code, but of course it did not work within dynare!

Is there any possibility to do it? In genera, is it possible to say the model to use certain equations at certain moments, and others at other moments?
Can I for example set some parameters at different values with if statements? (say if the central bank is conservative then the inflation parameter is such, if the central bank is not, then the inflation parameter is something else


I post an update:
I found that if statements can be included with @#if and so on. But it also seems to me that this can only work for parameter values, not for values taken by the endogenous variables.
In other words, I could solve the “monetary policy” question (if cb conservative do x, if cb loose, do y). But I cannot do what to me was more important, i.e. tell the model to change dynamic equation past a debt threshold.

I am afraid that the latter problem is unsolvable…

Dear Francesco

I am no expert on this but maybe it helps you find your way.

I share your interpretation for the usage of @#if. It’s only useful to make distinctions a priori, not endogenously.

Maybe this gets you going:
In general, Dynare knows the following functions (“if” not being one of them):
dynare.org/DynareWiki/ListOf … lFunctions

There is also the “external functions” command through which one can integrate other Matlab routines


I am wondering if you could solve the problem? I am facing something similar… I need to set an if statement which depends on a variable, but Dynare does not give me the solution! I get the error that FEx is unknown…

CFEx = (x-Cx(-1))/x;
FEx = CFEx^2;

@#if FEx(-1)>= 1
alpha_x = 0;
alpha_x = (1-(FEx(-1))^2)^0.5;

Sorry, but this is not possible within the context the stochastic simulations in Dynare. The reason is that your policy function will have a kink and be non-differentiable. This is inconsistent with perturbation solution techniques that rely on Taylor approximations.


I have different specifications of investment adjustment costs and want to use @# to choose between them in the model block. In the preambel, the marker has to be defined, e.g., @# define cee = 0
However, I want to choose the specification in an external parameter file, where I set all my parameters. I thought, I could then pass on the parameter value to cee, however, that does not work:

parameters paramcee;
paramcee =0;
@# define cee = paramcee

I get the error message “Unknown variable: paramcee”.

What could I do?

Thanks in advance!

The way I do it is to define an indicator as a parameter in Dynare and then use that parameter in an if clause within the external file:

@#if cee == 1

Thank you for your answer. However, I don’t entirely get it what you suggested. What do you specify in the .mod file as parameter, cee or cee_indicator?

So right now, I’m working with two files which I do not modify: a .mod file and an .m file containing the baseline calibration. The parameters specified in benchmarkcalibration.m and stored in parameterfile_comparison.mat are loaded into the Dynare file by using the command (inside the .mod file): load parameterfile_comparison;
I’m working with two specifications of investment adjustment costs, so my model block contains, for example, an equation
f1 = cee * eta_i/2 * ((In1+I1_ss)/(In1(-1)+I1_ss) -1)^2 +
(1-cee) * eta_i/2 * (exp(I1)/(deltaexp(K1(-1)))-1)^2 * deltaexp(K1(-1))/exp(I1) ;
And cee is the parameter indicating which adjustment costs I’m using.

Now, when I want to plot IR for the two specifications of investment ajustment costs I have a third file which “dynares” my .mod file and contains the following lines:

run benchmarkcalibration_comparison;
cee = 1;
save parameterfile_comparison cee -append;
dynare investmentNK.mod noclearall;

cee = 0;
save parameterfile_comparison cee -append;
dynare investmentNK.mod noclearall;

Works fine, however, now I want to look at a third version of inv. adj. costs and for that I need the if statement in the .mod file. Can I do it analogously to how I did it before?