# Simulated method of moments using dynare

**URL:** <https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497>\
**Category:** SMM/GMM/IRF-Matching\
**Created:** [23 November 2022 04:04 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497 "2022-11-23T04:04:58Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![amina0621](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@amina0621](https://forum.dynare.org/u/amina0621)\
**Post date:** [23 November 2022 04:04 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/1 "2022-11-23T04:04:58Z")

</div>

Hello,

I am running to understand about SMM [DSGE\_mod/Born\_Pfeifer\_2014 at master · JohannesPfeifer/DSGE\_mod · GitHub](https://github.com/JohannesPfeifer/DSGE_mod/tree/master/Born_Pfeifer_2014)

First you run the code by setting recalibration and estimation to 0 then change to 1 to find values for sigma\_x, phipar, D\_bar, and Phi.

1. In Born\_Pfeifer\_RM\_Comment.mod, the values for sigma\_x, phipar, D\_bar, and Phi are written already which is the same as values from running smm\_diff\_function. What is smm\_diff\_function doing if we know values already in original mod file?

2. simulated\_moments have three values while moments\_emp have 8 values, should they be equal when simulating?

3. In simult\_FGRU.m, they talk about exogenous states sigma\_r, sigma\_tb, eps\_r, eps\_tb, X. Are they playing any role to find values for sigma\_x, phipar, D\_bar, and Phi?

Thanks

---

<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 November 2022 16:07 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/2 "2022-11-23T16:07:39Z")

</div>

The code you are looking at is a replication file for an article.

1. Minimizing the `smm_diff_function` requires some starting values. We provided the values we found as starting values, but you should get the same with other reasonable starting values.
2. No, the 8 empirical moments are the ones used for the paper, but only four of them are matched. The moments at the optimum should be reasonably close to the empirical ones. There are four targets targeted with four parameters. If this were a linear equation system, you could typically find an exact solution. For practical applications, the fit will not be perfect.
3. I don’t understand the question.

---

<div class="post-metadata">

**Author:** ![amina0621](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@amina0621](https://forum.dynare.org/u/amina0621)\
**Post date:** [23 November 2022 16:25 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/3 "2022-11-23T16:25:17Z")

</div>

Thank you for your reply and explanation.  
Lines 115-119 in simult\_FGRU.m were mentioning about sigma\_r, sigma\_tb, eps\_r, eps\_tb, X. I thought sigma\_x, phipar, D\_bar, and Phi would be used in lines 115-119 since they are the parameter values to find?

---

<div class="post-metadata">

**Author:** ![amina0621](https://forum.dynare.org/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@amina0621](https://forum.dynare.org/u/amina0621)\
**Post date:** [23 November 2022 21:52 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/4 "2022-11-23T21:52:18Z")

</div>

I want to match theoretical moments from dynare to empirical data. Is working with SMM the right approach to find parameters that match theoretical moments to data?

---

<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 November 2022 09:15 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/5 "2022-11-24T09:15:09Z")

</div>

1. Dynare 5 has a `method_of_moments`-command to do such a matching.
2. The mentioning of the shock is necessary for the simulation of the model. It’s specific to the replication of the original paper. Usually, you can use generic Dynare codes for that.

---

<div class="post-metadata">

**Author:** ![HouseC](https://forum.dynare.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HouseC](https://forum.dynare.org/u/HouseC)\
**Post date:** [4 January 2023 08:37 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/6 "2023-01-04T08:37:57Z")

</div>

Hi Dears,

It is great to know that Dynare 5 has the `method_of_moments` command. I read the dynare manual and want to figure out it is possible to include the loglinear option, like the `stoch_simul` and `estimation` block.  
@jpfeifer @wmutschl

Best  
Sihao

---

<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:** [5 January 2023 11:45 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/7 "2023-01-05T11:45:15Z")

</div>

No. At the current stage, the loglinear options is not supported. You need to append the logarithms of the necessary variables.

---

<div class="post-metadata">

**Author:** ![HouseC](https://forum.dynare.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HouseC](https://forum.dynare.org/u/HouseC)\
**Post date:** [5 January 2023 11:58 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/8 "2023-01-05T11:58:05Z")

</div>

Hi Dear Pfeifer,

thanks for the confirmation. Looking forward to seeing that this option is included in near future.

Best,  
Sihao

---

<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:** [5 January 2023 12:05 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/9 "2023-01-05T12:05:42Z")

</div>

We are not currently planning on enabling this option as it would only work at `order=1` and there is an easy workaround.

---

<div class="post-metadata">

**Author:** ![HouseC](https://forum.dynare.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HouseC](https://forum.dynare.org/u/HouseC)\
**Post date:** [5 January 2023 12:18 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/10 "2023-01-05T12:18:12Z")

</div>

Get it now!

---

<div class="post-metadata">

**Author:** ![HouseC](https://forum.dynare.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HouseC](https://forum.dynare.org/u/HouseC)\
**Post date:** [9 January 2023 09:47 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/11 "2023-01-09T09:47:09Z")

</div>

Hi Dears

Thanks again for developing a toolbox for method of moments in Dynare. I learn a lot from the tutorial in Youtube as well as the corresponding sections in Dynare manual.

While I go though the sample code (which is available here: [https://mutschler.eu/files/estimation/dynare-summer-school-2021/RBC\_MoM.zip](https://mutschler.eu/files/estimation/dynare-summer-school-2021/RBC_MoM.zip)). I have two classification problems.

First, the data used are  
[RBC\_Data\_2.mat](https://forum.dynare.org/uploads/short-url/sgPq8ddmnkD9njKsepRq5aLtUlP.mat) (21.8 KB) . We can see that both c, n and iv have negative values. What is the treatment behind this data? Demeaned or hp filtered? The data is already measured in the percentage?

Second, in the option of `method_of_moments` , the Dynare manual says that the default is not set `logdata`. It implies that Dynare will applies the 𝑙𝑜𝑔 transformation to the provided data? Which make no sense since both c, n and iv have negative value in the data. So I’m wondering what is the role of logdata in the `method_of_moments` block, and when should we choose to set `logdata=1`?

@jpfeifer @wmutschl

Best,  
Sihao

---

<div class="post-metadata">

**Author:** ![wmutschl](https://forum.dynare.org/user_avatar/forum.dynare.org/wmutschl/32/18464_2.png) [@wmutschl](https://forum.dynare.org/u/wmutschl)\
**Post date:** [9 January 2023 10:51 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/12 "2023-01-09T10:51:47Z")

</div>

Hi,

1. the data I used in the video and example files is simulated level data from the same mod file.

2. I did not set the logdata option in the example (the option is commented out), so I am not sure what the problem is?

---

<div class="post-metadata">

**Author:** ![wmutschl](https://forum.dynare.org/user_avatar/forum.dynare.org/wmutschl/32/18464_2.png) [@wmutschl](https://forum.dynare.org/u/wmutschl)\
**Post date:** [9 January 2023 10:53 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/13 "2023-01-09T10:53:45Z")

</div>

> [@HouseC](#):
>
> when should we choose to set `logdata=1`?

Dynare applies the 𝑙𝑜𝑔 transformation to the provided data if a log-linearization of the model is requested (`loglinear` option) unless `logdata` option is used. This option is necessary if the user provides data already in logs, otherwise the 𝑙𝑜𝑔 transformation will be applied twice (this may result in complex data).

---

<div class="post-metadata">

**Author:** ![HouseC](https://forum.dynare.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HouseC](https://forum.dynare.org/u/HouseC)\
**Post date:** [9 January 2023 11:07 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/14 "2023-01-09T11:07:16Z")

</div>

Thanks, Willi

This is the part I feel confused.

First of all, in the `method of moment` block, no `loglinear` option will be available.  
And, in your shared example code, you did not set the logdata option. With this specification, will the dynare applies the 𝑙𝑜𝑔 transformation to the provided data? I guess the answer is no, right? The provided data is a level data for variable c, iv and n.  
And if the answer is no, under what condition will the logdata command be used, provided that no `loglinear` option will be available?

Best,  
Sihao

---

<div class="post-metadata">

**Author:** ![wmutschl](https://forum.dynare.org/user_avatar/forum.dynare.org/wmutschl/32/18464_2.png) [@wmutschl](https://forum.dynare.org/u/wmutschl)\
**Post date:** [9 January 2023 11:31 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/15 "2023-01-09T11:31:48Z")

</div>

The `logdata` option in the `method_of_moments` command is only relevant IF you use the loglinear option.

The `loglinear` option needs to be provided to the `model` block. Then dynare internally does a log transformation on ALL variables in the model, which is sometimes useful, but mostly doesn’t work as we often have variables where it is not a good idea to do a log transform. So in general, don’t use the `loglinear` option (unless you have a very specific usecase and model) and rather define auxiliary variables and equations for those variables for which you want to look at the log of.

So in my example: 1) no loglinear option was used in the model block and 2) no logdata option was used in the method\_of\_moments block. So dynare doesn’t do any transformation for you.

---

<div class="post-metadata">

**Author:** ![HouseC](https://forum.dynare.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HouseC](https://forum.dynare.org/u/HouseC)\
**Post date:** [9 January 2023 11:43 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/16 "2023-01-09T11:43:47Z")

</div>

Hi Willi,

Many thanks for your prompt response. It clarifies my concerns. I almost forgot that it is possible to specify a loglinear model using `model(linear)` in the `model` block.

Best,  
Sihao

---

<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:** [30 January 2026 09:30 UTC](https://forum.dynare.org/t/simulated-method-of-moments-using-dynare/21497/17 "2026-01-30T09:30:01Z")

</div>

4 posts were split to a new topic: [Identifying volatility shocks using method\_of\_moments](https://forum.dynare.org/t/identifying-volatility-shocks-using-method-of-moments/28246)
