Page 1 of 1

If statements within block model

PostPosted: Sat Jan 07, 2012 3:35 pm
by cesco
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 = delta1*0.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

Re: If statements within block model

PostPosted: Mon Jan 09, 2012 1:32 pm
by cesco
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...

Re: If statements within block model

PostPosted: Tue Jan 17, 2012 3:56 pm
by johannes.fritz
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):
http://www.dynare.org/DynareWiki/ListOf ... lFunctions

There is also the "external functions" command through which one can integrate other Matlab routines
http://www.dynare.org/DynareWiki/ExternalFunctions

Regards
Johannes

Re: If statements within block model

PostPosted: Tue Jul 21, 2015 5:32 pm
by Sara
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;

Re: If statements within block model

PostPosted: Wed Jul 22, 2015 5:08 am
by jpfeifer
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.