# Estimation RBC stochastic model

**URL:** <https://forum.dynare.org/t/estimation-rbc-stochastic-model/3631>\
**Category:** ML/Bayesian estimation\
**Created:** [19 January 2014 23:01 UTC](https://forum.dynare.org/t/estimation-rbc-stochastic-model/3631 "2014-01-19T23:01:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![omid\_ie](https://forum.dynare.org/letter_avatar_proxy/v4/letter/o/dc4da7/32.png) [@omid\_ie](https://forum.dynare.org/u/omid_ie)\
**Post date:** [19 January 2014 23:01 UTC](https://forum.dynare.org/t/estimation-rbc-stochastic-model/3631/1 "2014-01-19T23:01:15Z")

</div>

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 🙂  
[Dataformatlabmoney.xls](https://forum.dynare.org/uploads/default/original/2X/7/7b090c92c110ae8011aa215ef06a2e7be13e0484.xls) (20.5 KB)  
[test.mod](https://forum.dynare.org/uploads/default/original/2X/f/f3e00f21cfa53b57d0aa8aef9f5a3f52126837cb.mod) (1.94 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [20 January 2014 09:22 UTC](https://forum.dynare.org/t/estimation-rbc-stochastic-model/3631/2 "2014-01-20T09:22:58Z")

</div>

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. [[Bayesian Estimation and Steady State Updating](https://forum.dynare.org/t/bayesian-estimation-and-steady-state-updating/2787/1)) and “Remark 14 (initval vs. steady\_state\_model vs. steadystate-file)” in [sites.google.com/site/pfeiferecon/Pfeifer\_2013\_Observation\_Equations.pdf](https://sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf).

In your case, try using a different solve\_algo by putting e.g.

```auto

```

before your estimation command.

Finally, using only two observations is odd.

---

<div class="post-metadata">

**Author:** ![omid\_ie](https://forum.dynare.org/letter_avatar_proxy/v4/letter/o/dc4da7/32.png) [@omid\_ie](https://forum.dynare.org/u/omid_ie)\
**Post date:** [20 January 2014 10:39 UTC](https://forum.dynare.org/t/estimation-rbc-stochastic-model/3631/3 "2014-01-20T10:39:13Z")

</div>

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 ☹

---

<div class="post-metadata">

**Author:** ![omid\_ie](https://forum.dynare.org/letter_avatar_proxy/v4/letter/o/dc4da7/32.png) [@omid\_ie](https://forum.dynare.org/u/omid_ie)\
**Post date:** [20 January 2014 11:14 UTC](https://forum.dynare.org/t/estimation-rbc-stochastic-model/3631/4 "2014-01-20T11:14:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [20 January 2014 11:35 UTC](https://forum.dynare.org/t/estimation-rbc-stochastic-model/3631/5 "2014-01-20T11:35:27Z")

</div>

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:

```auto
k=((beta/gamma-(1-delta))/alpha)^(1/(alpha-1));
```

So whenever beta changes, so does the steady state for k. You said in initval

```auto

```

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

---

<div class="post-metadata">

**Author:** ![omid\_ie](https://forum.dynare.org/letter_avatar_proxy/v4/letter/o/dc4da7/32.png) [@omid\_ie](https://forum.dynare.org/u/omid_ie)\
**Post date:** [20 January 2014 11:47 UTC](https://forum.dynare.org/t/estimation-rbc-stochastic-model/3631/6 "2014-01-20T11:47:01Z")

</div>

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]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)(2log(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;

[/code]

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

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [20 January 2014 12:07 UTC](https://forum.dynare.org/t/estimation-rbc-stochastic-model/3631/7 "2014-01-20T12:07:54Z")

</div>

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

` 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.
