# Stoch\_simul works but estimation does not

**URL:** <https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194>\
**Category:** Dynare help (legacy posts)\
**Created:** [24 December 2015 11:53 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194 "2015-12-24T11:53:15Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuixing](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@shuixing](https://forum.dynare.org/u/shuixing)\
**Post date:** [24 December 2015 11:53 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/1 "2015-12-24T11:53:15Z")

</div>

hi

while I use stoch\_simul for a fully calibrated model the model seems to work well,

but if I use observations to estimae some parameters then a problem always exists:

POSTERIOR KERNEL OPTIMIZATION PROBLEM!  
(minus) the hessian matrix at the “mode” is not positive definite!  
=\> posterior variance of the estimated parameters are not positive.  
You should try to change the initial values of the parameters using  
the estimated\_params\_init block, or use another optimization routine.  
Warning: The results below are most likely wrong!

> In dynare\_estimation\_1 at 458  
> In dynare\_estimation at 70  
> In lcmr at 304  
> In dynare at 120

MODE CHECK

Fval obtained by the minimization routine: -655.668810

Most negative variance -284255.670560 for parameter 1 (e\_epsil = 0.006506)  
Warning: Matrix is close to singular or badly scaled.  
Results may be inaccurate. RCOND = 1.757306e-016.

> In dynare\_estimation\_1 at 473  
> In dynare\_estimation at 70  
> In lcmr at 304  
> In dynare at 120

what seems to be the problem?

---

<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:** [26 December 2015 10:16 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/2 "2015-12-26T10:16:41Z")

</div>

Please search the forum on this. A first indication can derived from the mode-check plots.

---

<div class="post-metadata">

**Author:** ![shuixing](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@shuixing](https://forum.dynare.org/u/shuixing)\
**Post date:** [29 December 2015 11:42 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/3 "2015-12-29T11:42:17Z")

</div>

> [@jpfeifer](#):
>
> Please search the forum on this. A first indication can derived from the mode-check plots.

thanks professor jpfeifer, a few parameters’ mode chek plot do have red dots within some range, so should I impose parameters bound restriction?

---

<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:** [29 December 2015 15:08 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/4 "2015-12-29T15:08:29Z")

</div>

Red dots are not an issue. The question is whether the modes are at the peaks of the posterior and whether there are vertical likelihood kernels.

---

<div class="post-metadata">

**Author:** ![shuixing](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@shuixing](https://forum.dynare.org/u/shuixing)\
**Post date:** [2 January 2016 04:54 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/5 "2016-01-02T04:54:00Z")

</div>

> [@jpfeifer](#):
>
> Red dots are not an issue. The question is whether the modes are at the peaks of the posterior and whether there are vertical likelihood kernels.

thanks dear professor jpfeifer, you are always so helpful, just one more question, the dynare manul does not provide enough details to deal with ouput of dynare ,for example where is the smoothed shock or variable saved and how to feed some smoothed shocks into simulation while shut off other shocks, so where can I find some learning materials for a further study about things like these, thanks jpfeifer.

---

<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:** [2 January 2016 07:25 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/6 "2016-01-02T07:25:32Z")

</div>

After estimation, you can find them in oo\_.SmoothedShocks and oo\_.SmoothedVariables, see the bottom of [dynare.org/manual/index\_27.html](http://www.dynare.org/manual/index_27.html)  
Regarding the feeding in of shocks, see [[Simulate a model using smoothed shocks](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/1))

---

<div class="post-metadata">

**Author:** ![shuixing](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@shuixing](https://forum.dynare.org/u/shuixing)\
**Post date:** [13 January 2016 11:43 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/7 "2016-01-13T11:43:31Z")

</div>

[quote=“jpfeifer”]After estimation, you can find them in oo\_.SmoothedShocks and oo\_.SmoothedVariables, see the bottom of [dynare.org/manual/index\_27.html](http://www.dynare.org/manual/index_27.html)  
Regarding the feeding in of shocks, see [[Simulate a model using smoothed shocks](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/1))[/quote]

finally I can login this forum… I really appreciate your hellp,thanks, professor jpfeifer!

---

<div class="post-metadata">

**Author:** ![shuixing](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@shuixing](https://forum.dynare.org/u/shuixing)\
**Post date:** [13 January 2016 13:04 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/8 "2016-01-13T13:04:48Z")

</div>

[quote=“jpfeifer”]After estimation, you can find them in oo\_.SmoothedShocks and oo\_.SmoothedVariables, see the bottom of [dynare.org/manual/index\_27.html](http://www.dynare.org/manual/index_27.html)  
Regarding the feeding in of shocks, see [[Simulate a model using smoothed shocks](https://forum.dynare.org/t/simulate-a-model-using-smoothed-shocks/3008/1))[/quote]

I add the code  
ex\_=[oo\_.SmoothedShocks.Median.e\_a oo\_.SmoothedShocks.Median.e\_m]  
y0=oo\_.dr.ys;  
dr=oo\_.dr  
iorder=1;  
y\_=simult\_(y0,dr,ex\_,iorder);’

in the mod.file after the estimation command line, but it reports the following error

??? Reference to non-existent field ‘Median’.

Error in ==\> lcmr at 305  
ex\_=[oo\_.SmoothedShocks.Median.e\_a oo\_.SmoothedShocks.Median.e\_m]

Error in ==\> dynare at 120  
evalin(‘base’,fname) ;

is there any details I misunderstand?

---

<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:** [14 January 2016 09:30 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/9 "2016-01-14T09:30:53Z")

</div>

Please check which fields in oo\_.SmoothedShocks exist. Maybe you only have the mean there.

---

<div class="post-metadata">

**Author:** ![shuixing](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@shuixing](https://forum.dynare.org/u/shuixing)\
**Post date:** [14 January 2016 15:05 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/10 "2016-01-14T15:05:52Z")

</div>

> [@jpfeifer](#):
>
> Please check which fields in oo\_.SmoothedShocks exist. Maybe you only have the mean there.

dear jpfeifer, I did not do anything wiht the result just add the code lines, so the oo\_.SmoothedShocks are still in oo\_ field.

---

<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:** [14 January 2016 15:22 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/11 "2016-01-14T15:22:24Z")

</div>

I said you should check the subfields and whether they exist. Maybe there is only

```auto

```

and not

```auto

```

---

<div class="post-metadata">

**Author:** ![shuixing](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@shuixing](https://forum.dynare.org/u/shuixing)\
**Post date:** [16 January 2016 03:04 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/12 "2016-01-16T03:04:47Z")

</div>

[quote=“jpfeifer”]I said you should check the subfields and whether they exist. Maybe there is only

```auto

```

and not

```auto

```

hi professor jpfeifer,I have checked, and it seems only oo\_.SmoothedShocks exist.

---

<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:** [19 January 2016 09:41 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/13 "2016-01-19T09:41:42Z")

</div>

So you did not run the MCMC. In this case, take the results in

```auto

```

---

<div class="post-metadata">

**Author:** ![shuixing](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@shuixing](https://forum.dynare.org/u/shuixing)\
**Post date:** [21 January 2016 13:56 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/14 "2016-01-21T13:56:31Z")

</div>

[quote=“jpfeifer”]So you did not run the MCMC. In this case, take the results in

```auto

```

thanks professor Jpeifer,  
so I use code:

ex\_=[oo\_.SmoothedShocks];  
y0=oo\_.dr.ys;  
dr=oo\_.dr;  
iorder=1;  
y\_=simult\_(y0,dr,ex\_,iorder);

but I get error  
??? Undefined function or method ‘mtimes’ for input arguments of type ‘struct’.

Error in ==\> simult\_ at 99  
epsilon = dr.ghu\*transpose(ex\_);

Error in ==\> lcmr at 324  
y\_=simult\_(y0,dr,ex\_,iorder);

Error in ==\> dynare at 120  
evalin(‘base’,fname) ;

my model is loglinearized by hand, so I think maybe iorder=1 is wrong ,then I change iorder=0,but I only get two columns of zeros in y\_, what seems to be the problem?

---

<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:** [24 January 2016 19:10 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/15 "2016-01-24T19:10:54Z")

</div>

You need to sort this out yourself by checking the content of

```auto

```

The error message tells you that it is a structure. But you claimed that there are no subfields before.

---

<div class="post-metadata">

**Author:** ![shuixing](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/bc79bd/32.png) [@shuixing](https://forum.dynare.org/u/shuixing)\
**Post date:** [28 January 2016 11:16 UTC](https://forum.dynare.org/t/stoch-simul-works-but-estimation-does-not/5194/16 "2016-01-28T11:16:51Z")

</div>

[quote=“jpfeifer”]You need to sort this out yourself by checking the content of

```auto

```

The error message tells you that it is a structure. But you claimed that there are no subfields before.[/quote]

thanks professor J.Peifer, finally it works!
