# Simulate Estimation Of A Simple 3-eq Model

**URL:** <https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172>\
**Category:** ML/Bayesian estimation\
**Created:** [22 April 2022 02:10 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172 "2022-04-22T02:10:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kylekk](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/7feea3/32.png) [@Kylekk](https://forum.dynare.org/u/Kylekk)\
**Post date:** [22 April 2022 02:10 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/1 "2022-04-22T02:10:38Z")

</div>

Hi all,

I am new to Dynare, still having a hard time reading manual and other people’s codes. Forgive me if the question is super basic.

**My goal** : I am thinking about writing a Dynare file to both simulate and then estimate the same simple DSGE model, see if the parameter values vary at all (consistent with the identification results).  
I have a specific setup attached here, and some calibrated values to the parameters. I would love to generate the observables with this set of parameters and then estimate the model as if I don’t know the parameters.  
 ![image](https://forum.dynare.org/uploads/default/original/2X/4/47563a5083c76e8bf4834a7620450745007e3614.png)

**My question:** 1. I don’t know what command to use to generate y\_t, pi\_t, and i\_t and then save it in a data file. I guess stoch\_simul will do the simulation, but can I save the result and use it in the same mod file?  
2. I wrote the estimation part with some data file I found online just as an exercise. However, the results are weird even if identification test passed.  
_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._

1. Another thing I’m really curious about is even when people claim they are doing estimation, they have this calibration block. Why do we need that if the parameter priors are already set by the estimated\_params block?

[Data1.m](https://forum.dynare.org/uploads/short-url/8xU3daaUWDP7U30pHcv5OsOCM0y.m) (7.3 KB)  
[three\_eq\_nk.mod](https://forum.dynare.org/uploads/short-url/omATQDRiS43ModbBfIU4xIK84A8.mod) (1020 Bytes)

Thank you!

---

<div class="post-metadata">

**Author:** ![kofiemma](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kofiemma](https://forum.dynare.org/u/kofiemma)\
**Post date:** [22 April 2022 09:22 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/2 "2022-04-22T09:22:11Z")

</div>

> [@Kylekk](#):
>
> I don’t know what command to use to generate y\_t, pi\_t, and i\_t

Check the manual. Simulated variables are already saved.

---

<div class="post-metadata">

**Author:** ![kofiemma](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kofiemma](https://forum.dynare.org/u/kofiemma)\
**Post date:** [22 April 2022 09:28 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/3 "2022-04-22T09:28:11Z")

</div>

> [@Kylekk](#):
>
> Another thing I’m really curious about is even when people claim they are doing estimation, they have this calibration block. Why do we need that if the parameter priors are already set by the estimated\_params block?

Because you need to solve the model…thus making sure BK conditions are satisfied before estimating the parameters. If BK conditions are not satisfied, the estimation will not work either.

---

<div class="post-metadata">

**Author:** ![Kylekk](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/7feea3/32.png) [@Kylekk](https://forum.dynare.org/u/Kylekk)\
**Post date:** [22 April 2022 12:40 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/5 "2022-04-22T12:40:55Z")

</div>

Thank you, Emmanuel. The way I understand it, the BK condition only matters when solving a Linear Rational Expectation model? Are you saying the calibration values give the initial value of parameters that are used to check the BK condition? If there is an indeterminacy issue, will estimation go?

---

<div class="post-metadata">

**Author:** ![kofiemma](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kofiemma](https://forum.dynare.org/u/kofiemma)\
**Post date:** [22 April 2022 13:19 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/6 "2022-04-22T13:19:36Z")

</div>

Yes, the model must work in a calibrated version before you estimate it. It is your choice to use the parameters in the `parameters;` block as initial values for the estimation, or you can change it.

The parameters you specify in the `parameters;` block are not necessarily initial values for the estimation.

> [@Kylekk](#):
>
> If there is an indeterminacy issue, will estimation go?

No, it won’t. The model must be solved first. If there is no solution, then you cannot estimate it.

---

<div class="post-metadata">

**Author:** ![Kylekk](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/7feea3/32.png) [@Kylekk](https://forum.dynare.org/u/Kylekk)\
**Post date:** [22 April 2022 14:07 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/7 "2022-04-22T14:07:52Z")

</div>

Thanks again, Emmanuel. I guess indeed I am a little confused by the seemingly similar block names.  
Correct me if I am wrong.  
The calibrated parameter; block is used to first solve the model, but not used any further.  
The parameters; block is used to declare params, but I can also initialize their values in that block?  
And the estimated\_params; is where I put prior distributions for estimation.

What if there’s a conflict between second and third block? which initial value would then be used? A random draw from prior or the parameters; block?  
And in addition, even if a solution exists, when an indeterminacy issue exists (non-uniqueness), I guess you are saying Dynare would not give me the continuum of equilibria?  
Thank you for your time!

---

<div class="post-metadata">

**Author:** ![kofiemma](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kofiemma](https://forum.dynare.org/u/kofiemma)\
**Post date:** [22 April 2022 14:46 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/8 "2022-04-22T14:46:06Z")

</div>

> [@Kylekk](#):
>
> The calibrated parameter; block is used to first solve the model, but not used any further.

Yes. If you want to use those parameters as initial values for estimation, you must use the command `use_calibration;`…see manual.

> [@Kylekk](#):
>
> And the estimated\_params; is where I put prior distributions for estimation.

Yes, prior distribution and initial values of parameters for estimation…see manual.

> [@Kylekk](#):
>
> What if there’s a conflict between second and third block? which initial value would then be used?

Initial values for estimation are specified in `estimated_params;` block. If you want to use calibrated parameters as initial values, you must specify `use_calibration;`.

> [@Kylekk](#):
>
> And in addition, even if a solution exists, when an indeterminacy issue exists (non-uniqueness), I guess you are saying Dynare would not give me the continuum of equilibria?

Dynare will only give you unique solution if one exist.

---

<div class="post-metadata">

**Author:** ![Kylekk](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/7feea3/32.png) [@Kylekk](https://forum.dynare.org/u/Kylekk)\
**Post date:** [22 April 2022 16:33 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/9 "2022-04-22T16:33:37Z")

</div>

I see. If I am to use stoch\_simul(irf=60) y r pi, then it generates the response data from a one-time shock. That is not what I want. How could I generate a **simulated** data as in I would like to have different realizations of shocks each period as if the y, r, pi are from some realized shock process? Is `stoch_simul(order=1,periods=1000,simul_replic=1);` what I want?  
Also, do you know how to call `oo_.endo_simul` variable from the simulated result in the `estimation` command?  
Appreciate your help!

---

<div class="post-metadata">

**Author:** ![kofiemma](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/439d5e/32.png) [@kofiemma](https://forum.dynare.org/u/kofiemma)\
**Post date:** [23 April 2022 04:42 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/10 "2022-04-23T04:42:23Z")

</div>

Yes…check the workspace. If it is not there, read the manual, it is saved somewhere. Sorry, I don’t matlab with me now. But yes, it is saved somewhere.

---

<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:** [23 April 2022 15:39 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/11 "2022-04-23T15:39:17Z")

</div>

`periods=x` will get you simulated series that will also be stored under the names of the variables in the workspace. You can then use `datatomfile` as in line 229 of [examples/Ramsey\_Example.mod · master · Dynare / dynare · GitLab](https://git.dynare.org/Dynare/dynare/-/blob/master/examples/Ramsey_Example.mod)

---

<div class="post-metadata">

**Author:** ![Kylekk](https://forum.dynare.org/letter_avatar_proxy/v4/letter/k/7feea3/32.png) [@Kylekk](https://forum.dynare.org/u/Kylekk)\
**Post date:** [23 April 2022 16:21 UTC](https://forum.dynare.org/t/simulate-estimation-of-a-simple-3-eq-model/20172/12 "2022-04-23T16:21:08Z")

</div>

Excellent! Thank you professor!
