Define macro-variable depending on parameter value

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Define macro-variable depending on parameter value

Postby htxm1586 » Wed Feb 26, 2014 4:54 pm

I am running second order approximation and letting dynare to calculate unconditional utility. I'm using CRRA utility, specifying utility function depends on whether risk aversion parameter equals 1 or not. I'm trying to write the following code:

...
parameters rho
rho=1;
@#define logutility=rho
...
model;
@#if logutility
U=log(exp(c)-exp((1+epsilon)*h)/(1+epsilon))+beta*U(+1);
@#else
U=(exp(c)-exp((1+epsilon)*h)/(1+epsilon))^(1-rho)/(1-rho)+beta*U(+1);
@#endif
end;
...

However, Dynare returns msg "unknown variable rho". To my understanding, I cannot specify "@#define logutility=rho" because rho is a parameter, not a macro-variable, so it cannot show up within "@#define".

I wonder if there is a way to circumvent this problem?
htxm1586
 
Posts: 4
Joined: Wed Feb 26, 2014 2:30 pm

Re: Define macro-variable depending on parameter value

Postby jpfeifer » Sun Mar 02, 2014 11:40 am

Try the following
Code: Select all
parameters rho_par;

@#define rho=1

rho_par=rho;
...
model;
@#if rho==1
U=log(exp(c)-exp((1+epsilon)*h)/(1+epsilon))+beta*U(+1);
@#else
U=(exp(c)-exp((1+epsilon)*h)/(1+epsilon))^(1-
rho_par)/(1-
rho_par)+beta*U(+1);
@#endif
end;


You directly set rho for the preprocessor in the second line. From there, the value is assigned to the parameter rho_par, which you can then access.

This follows the example in agtrend.mod.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 4 guests