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=0;
invg=dsp;
else
dcur = delta10.05(b0-bstar);
invg = chi0*dsp;
end;

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

thanks!
Francesco

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
dynare.org/DynareWiki/ExternalFunctions

Regards
Johannes

Hi,
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;
@#esle
alpha_x = (1-(FEx(-1))^2)^0.5;
end;

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.

Hi,

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
    cee_indicator=1;
@#else
    cee_indicator=0;
@#endif

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)/(delta*exp(K1(-1)))-1)^2 * delta*exp(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?

Hi,

I have a similar type of question.

@#if true_stochastic_steady_state_IRFs

and complete command

@#if true_stochastic_steady_state_IRFs
burnin=5000; %periods for convergence
@#else
burnin=5000; %periods for convergence
@#endif

Does the above-mentioned command used for the external steady state file?

If I have my own steady-state guess within a mod file. Then how to modify the command?

Thanks,
E.

You need to provide more details and context. What are you trying to do and how far did you get?

Thank you,

I am working on the code of Basu and Bundick (2017) and I saw they have an external steady state file along with the earlier mentioned code. It works fine but I put my own guess for steady-state in the same file (does not want to use external SS file). Then how it will work?
I’m sorry it is a general question.

Thanks,
E.

But where is the problem in this case? Why do you even need the macroprocessor?

Hi,
I am running an external steady state file and came with the error. I am a beginner and do not know how to fix it. Any guidance, please?

Error: File: Essay_1_steadystate.m Line: 33 Column: 2
Assigning the function output to this expression is not supported.
Error in evaluate_steady_state_file (line 49)
[ys,params1,check] = h_steadystate(ys_init, exo_ss,M,options);
Error in evaluate_steady_state (line 210)
[ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, options,steadystate_check_flag);
Error in steady_ (line 55)
[steady_state,params,info] = evaluate_steady_state(oo_.steady_state,M_,options_,oo_,~options_.steadystate.nocheck);
Error in steady (line 80)
[oo_.steady_state,M_.params,info] = steady_(M_,options_,oo_);
Error in Essay_1.driver (line 504)
steady;
Error in dynare (line 293)
evalin(‘base’,[fname ‘.driver’]) ;
Essay_1.mod (15.5 KB)
Essay_1_steadystate.m (2.5 KB)

See

Thank you Professor, JPfeifer.

Hello,

Thanks for this answer, but I share the confusion of jojokre. What is the declared parameter here, cee or cee_indicator?

I’m trying to run the same model multiple times from a Matlab code, and I was trying to select different equations in the model block according to a global-kind-of variable that I set in Matlab. In this case: I’d declare the global variable opt = 1 in Matlab, then run the .mod file with option “noclearall” not to delete it, and within the .mod file define “@#define op = opt”

This is the model block’s if statement:

@#if op = 1
  tn = 0;                                                   % Lump sum
@#elseif op = 2
  tn = tn_ss + (0.5*(apport - gy_ss))/((1-alpha)*y);        % Current labor tax
@#elseif op = 3
  tn = tn_ss + (0.5*(apport(-3) - gy_ss))/((1-alpha)*y);    % Delayed labor tax
@#endif

Many thanks in advance

Can you provide your codes?