Page 1 of 1

Bansal-Yaron (2009) problem with the code

PostPosted: Thu Jul 15, 2010 5:35 am
by igorvele
I am trying to estimate Bansal-Yaron (2009) model but i´m getting this error

You did not declare endogenous variables after the estimation command.

It repeats a thousand times.
Can anyone tell me what´s wrong?
thanks!

Re: Bansal-Yaron (2009) problem with the code

PostPosted: Thu Jul 15, 2010 6:10 am
by jpfeifer
It's not an error but a warning. So you can ignore it. Instead, try naming your data-file differently from the Dynare model file.

Re: Bansal-Yaron (2009) problem with the code

PostPosted: Fri Jul 16, 2010 6:00 am
by igorvele
thanks!

another thing:

when i estimate BY(2004) model using mode_compute=6, i have this error:

STEADY: numerical initial values incompatible with the following equations
4 5

and it stops working


however, if i change mode_compute to 3, i got the same message, but dynare calculate posteriors and everything
why?

Re: Bansal-Yaron (2009) problem with the code

PostPosted: Fri Jul 16, 2010 6:50 am
by jpfeifer
Could you post the mod-file and the data-file? Note that you should always give valid starting values, irregardless of the way you compute the mode. Use the initval-block for this.
The error you got, may derive from several problems:
1. You forgot to initialize one of the parameters so Dynare set it to NaN, [] or 0.
2. You did not specify starting values for the steady state computation by using the initval-block. In this case, Dynare uses 0 as the starting values. In some cases, you divide in some equations by this variable, giving you this error. The same may happen if the starting values leads to taking the root of a negative number.
3. The same problem as is the case for the endogenous variables in 2 may happen if you use wrong initial values for the parameters.

Re: Bansal-Yaron (2009) problem with the code

PostPosted: Fri Jul 16, 2010 10:41 am
by igorvele
here it is!

//This is Bansal-Yaron (2004) model for US and Brazil

//endogenous variables
var c d pc pd x;

//exogenous variables
varexo ec ex ed;

//parameters
parameters beta gamma psi mu_c mu_d rho tau;
beta =0.95;
gamma =2;
psi =1.5;
mu_c =0.01;
mu_d =0.01;
rho =0.9;
tau =3;

model;
c = mu_c + x(-1) +ec;
d = mu_d + tau*x(-1) + ed ;
x = rho*x(-1) + ex;
pc = beta^((1-gamma)/(1-(1/psi)))*exp((-((1-gamma)/(1-(1/psi)))/psi)*c(+1)+(((1-gamma)/(1-(1/psi)))-1)*log(((1+pc(+1))/pc)*exp(c(+1))))*(1+pc(+1))*exp(c(+1));
pd = beta^((1-gamma)/(1-(1/psi)))*exp((-((1-gamma)/(1-(1/psi)))/psi)*c(+1)+(((1-gamma)/(1-(1/psi)))-1)*log(((1+pc(+1))/pc)*exp(c(+1))))*(1+pd(+1))*exp(d(+1));
end;

initval;
c=mu_c;
d=mu_d;
x=0;
pc=0.01;
pd=0.01;
ec=0;
ex=0;
ed=0;
end;

shocks;
var ec; stderr .01;
var ed; stderr .01;
var ex; stderr .01;
end;

check;
steady;

estimated_params;
beta ,NORMAL_PDF ,0.98 ,0.05;
gamma ,NORMAL_PDF ,2 ,0.50;
psi ,NORMAL_PDF ,1.6 ,0.5;
mu_c ,NORMAL_PDF ,0.01 ,0.005;
mu_d ,NORMAL_PDF ,0.01 ,0.005;
rho ,NORMAL_PDF ,0.98 ,0.05;
tau ,NORMAL_PDF ,3 ,0.7;

stderr ed ,INV_GAMMA_PDF ,0.01 , .02;
stderr ex ,INV_GAMMA_PDF ,0.001 , .02;
stderr ec ,INV_GAMMA_PDF ,0.001 , .02;
end;

varobs c d pd;
estimation(datafile=databy04,xls_sheet=ready,xls_range=g2:i121,mode_compute=3,mh_replic=1000,mh_nblocks=2);

Re: Bansal-Yaron (2009) problem with the code

PostPosted: Fri Jul 16, 2010 6:36 pm
by jpfeifer
I guess your true problem is with your priors. E.g. , you should not use a normal prior for beta. The reason is that beta is always between 0 and 1, but a normal distribution has the whole real line as its support. The correct prior here would be a beta distribution. If the estimation tries a value for beta that is negative, computing
Code: Select all
beta^((1-gamma)/(1-(1/psi)))

might involve taking the root of a negative number. The same problem with priors having the wrong support may apply to other parameters as well, e.g. for autoregressive parameters like rho which should be between -1 and 1.