Page 1 of 1

Estimation RBC stochastic model

PostPosted: Sun Jan 19, 2014 11:01 pm
by omid_ie
Dear My friends;

I wana estimate this stochastic model but encounter a error :
Error using lnsrch1 (line 71)
Some element of Newton direction isn't finite. Jacobian maybe singular or there is a problem with initial values

The code and data file is attached.
I just need an estimation and the computation model doesn't matter. I checked all methods :)

Re: Estimation RBC stochastic model

PostPosted: Mon Jan 20, 2014 9:22 am
by jpfeifer
Your problem is that your initial values for steady state computation are not good for different parameters. Hence, during estimation, Dynare often cannot compute the steady states. See e.g. http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=4148 and "Remark 14 (initval vs. steady_state_model vs. steadystate-file)" in https://sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf.

In your case, try using a different solve_algo by putting e.g.

Code: Select all
options_.solve_algo=3;

before your estimation command.

Finally, using only two observations is odd.

Re: Estimation RBC stochastic model

PostPosted: Mon Jan 20, 2014 10:39 am
by omid_ie
Thanks. Is it possible to describe a little specific?
u said : "initial values for steady state...are not good different parameters"
I have two steady state in my code: first one in "initval" Block and second one in "estimated_params_init" ??
I used ur advice code and now I have this error:
Error using chol
Matrix must be positive definite.
By the way ur google link is not working :(

Re: Estimation RBC stochastic model

PostPosted: Mon Jan 20, 2014 11:14 am
by omid_ie
also this error :
TEADY: The Jacobian contains Inf or NaN. The problem arises from:

STEADY: Derivative of Equation 8 with respect to Variable l (initial value of l: 0.333)

STEADY: The problem most often occurs, because a variable with
STEADY: exponent smaller than 1 has been initialized to 0. Taking the derivative
STEADY: and evaluating it at the steady state then results in a division by 0.

Re: Estimation RBC stochastic model

PostPosted: Mon Jan 20, 2014 11:35 am
by jpfeifer
Sorry, I corrected the typo and the link. The steady state is about the endogenous variables of the model, so you only have one. The estimated_params_init block is about parameters.
The problem is the following. Abstracting from labor for the moment, your model for example implies a steady state for capital of:
Code: Select all
k=((beta/gamma-(1-delta))/alpha)^(1/(alpha-1));

So whenever beta changes, so does the steady state for k. You said in initval
Code: Select all
k=0.890299;

For some betas this value will be good, for others it will be poor. Thus, try to analytically compute the steady state.

Re: Estimation RBC stochastic model

PostPosted: Mon Jan 20, 2014 11:47 am
by omid_ie
Thanks again;

But if u check my inital values I am using the same K :)
my problem is with the estimation part - the last line of my code. My steady state code is working properly.

I am sharing the code here to ease the discussion.


Code: Select all
var y, c, k, s, i, l, m, pi, w, ir, zeta, theta;
varexo tfp, nu;

parameters alpha, beta, rho, delta, gamma, barl, mi, eta, csi, hatzeta;

beta=0.96;
alpha=.33;
delta=0.1;
rho=0.994022170958;
gamma=1.030231005;
barl=1/3;
mi=0.5;
eta=0.180016;
csi=0.00001;
hatzeta=0.006331062557318192;

model;
gamma*(1/c)=beta*(1/c(+1))*(1-delta+alpha*exp(s(+1))*(k/l(+1))^(alpha-1));
gamma*k=(1-delta+alpha*exp(s)*(k(-1)/l)^(alpha-1))*k(-1)+w*l-c;
(1-mi)/m=(mi/c)*(ir/1+ir);
1-delta+alpha*exp(s(+1))*k^(alpha-1)*l(+1)^(1-alpha)=(1+ir)/(1+pi(+1));
s=rho*s(-1)+tfp;
y=exp(s)*k(-1)^alpha*l^(1-alpha);
i=y-c;
log(w)=(1/2)*log(w(+1))+(1/2)*log(1+pi(+1))+(1/2)*log(w(-1))-(1/2)*log(1+pi)+(csi/2)*(2*log(l/barl)+log(l(+1)/l)+log(l(-1)/l));
w=(1-alpha)*exp(s)*(k(-1)/l)^(alpha);
m=exp(zeta)*m(-1)/(gamma*(1+pi));
zeta-hatzeta=theta;
theta=eta*theta(-1)+nu;
end;


initval;
c=0.346541;
i=0.115944;
ir=0.04828;
k=0.890299;
l=0.333;
m=3.56;
pi=-0.02318;
s=0;
theta=0;
w=0.92497;
y=0.458;
zeta=0.006331062557318192;
nu=0;
tfp=0;
end;

steady;


estimated_params;

beta, normal_pdf, 0.96, 0.1;
alpha, beta_pdf, 0.3, 0.1;
delta, normal_pdf, 0.1, 0.05;
rho, beta_pdf, 0.99, 0.05;
mi, normal_pdf, 0.5, 0.3;
gamma, normal_pdf, 1.03023, 0.3;
eta , beta_pdf, 0.18, 0.15;
hatzeta, beta_pdf,0.00633,0.05;
csi, beta_pdf, 0.5, 0.05;
stderr nu, inv_gamma_pdf, 0.02, inf;
stderr tfp, inv_gamma_pdf, 0.02, inf;
end;

shocks;
var nu; stderr 0.0046;
var tfp; stderr 0.0140;

end;

stoch_simul(irf=50, order=1, nomoments);

varobs y, k;


estimated_params_init;
stderr tfp, 0.0140;
%stderr nu, 0.0046;

beta, 0.96;
alpha, 0.33;
delta, 0.1;
rho, 0.994022170958;
gamma, 1.030231005;
barl, 0.333;
mi, 0.5;
eta, 0.180016;
csi, 0.5;
hatzeta, 0.006331062557318192;
end;

estimation(datafile = Dataformatlabmoney, first_obs=1, plot_priors=1, mh_nblocks = 2, nobs=100, mode_compute=10, mode_check, forecast=40)y, c, k, s, i, l, m, pi, w, ir, zeta, theta;



My aim is just considering some parameters as stochastic distribution and find an estimation of DSGE (Bayesian /montecarlo/Simulated annealing).

Re: Estimation RBC stochastic model

PostPosted: Mon Jan 20, 2014 12:07 pm
by jpfeifer
Within estimation for every parameter draw for which the likelihood is computed, Dynare needs to compute a new steady state for this parameter combination. You INITIAL steady state is OK, but this does not hold for the parameter draws DURING estimation.

You should simply be listening to me. Try using
Code: Select all
   options_.solve_algo=3;

before the estimation command.

Also, your priors are rather crazy. beta cannot be normally distributed. The same applies for delta.

If the Cholesky problem appears after mode-computation, try a different mode-finder ore manually specify a covariance matrix. That is now possible with Dynare 4.4. See the manual.