温馨提示：定期 清理浏览器缓存，可以获得最佳浏览体验。

**目录**

今天，在 Stata Blog 看到了一篇文章，使用一个简单范例介绍了 Stata 中如何估计 DSGE 模型的参数。

Dynamic stochastic general equilibrium (DSGE) models are used in macroeconomics to model the joint behavior of aggregate time series like inflation, interest rates, and unemployment. They are used to analyze policy, for example, to answer the question, “What is the effect of a surprise rise in interest rates on inflation and output?” To answer that question we need a model of the relationship among interest rates, inflation, and output. DSGE models are distinguished from other models of multiple time series by their close connection to economic theory. Macroeconomic theories consist of systems of equations that are derived from models of the decisions of households, firms, policymakers, and other agents. These equations form the DSGE model. Because the DSGE model is derived from theory, its parameters can be interpreted directly in terms of the theory.

In this post, I build a small DSGE model that is similar to models used for monetary policy analysis. I show how to estimate the parameters of this model using the new **dsge** command in Stata 15. I then shock the model with a contraction in monetary policy and graph the response of model variables to the shock.

[^1]: Clarida, R., J. Galí, and M. Gertler. 1999. The science of monetary policy: A new Keynesian perspective. Journal of Economic Literature 37: 1661–1707. [^2]: Woodford, M. 2003. Interest and Prices: Foundations of a Theory of Monetary Policy. Princeton, NJ: Princeton University Press.

A DSGE model begins with a description of the sectors of the economy to be modeled. The model I describe here is related to the models developed in Clarida, Galí, and Gertler (1999)[^1] and Woodford (2003)[^2]. It is a smaller version of the kinds of models used in central banks and academia for monetary policy analysis. The model has three sectors: households, firms, and a central bank.

Households consume output. Their decision making is summarized by an output demand equation that relates current output demand to expected future output demand and the real interest rate.

Firms set prices and produce output to satisfy demand at the set price. Their decision making is summarized by a pricing equation that relates current inflation (that is, the change in prices) to expected future inflation and current demand. The parameter capturing the degree to which inflation depends on output demand plays a key role in the model.

The central bank sets the nominal interest rate in response to inflation. The central bank increases the interest rate when inflation rises and reduces the interest rate when inflation falls.

The model can be summarized in three equations,

The variable

The endogenous variables

The two exogenous variables are modeled as first-order autoregressive processes,

which follows common practice.

In the jargon, endogenous variables are called control variables, and exogenous variables are called state variables. The values of control variables in a period are determined by the system of equations. Control variables can be observed or unobserved. State variables are fixed at the beginning of a period and are unobserved. The system of equations determines the value of state variables one period in the future.

We wish to use the model to answer policy questions. What is the effect on model variables when the central bank conducts a surprise increase in the interest rate? The answer to this question is to impose an impulse *ξ~t~* and trace out the effect of the impulse over time.

Before doing policy analysis, we must assign values to the parameters of the model. We will estimate the parameters of the above model using U.S. data on inflation and interest rates with dsge in Stata.

I fit the model using data on the U.S. interest rate and inflation rate. In a DSGE model, you can have as many observable control variables as you have shocks in the model. Because the model has two shocks, we have two observable control variables. The variables in a linearized DSGE model are stationary and measured in deviation from steady state. In practice, this means the data must be de-meaned prior to estimation. dsge will remove the mean for you.

I use the data in `usmacro2`

, which is drawn from the Federal Reserve Bank of St. Louis database.

```
. webuse usmacro2
```

To specify a model to Stata, type the equations using substitutable expressions.

```
. dsge (x = E(F.x) - (r - E(F.p) - z), unobserved) ///
(p = {beta}*E(F.p) + {kappa}*x) ///
(r = 1/{beta}*p + u) ///
(F.z = {rhoz}*z, state) ///
(F.u = {rhou}*u, state)
```

The rules for equations are similar to those for Stata’s other commands that work with substitutable expressions. Each equation is bound in parentheses. Parameters are enclosed in braces to distinguish them from variables. Expectations of future variables appear within the **E()** operator. One variable appears on the left-hand side of the equation. Further, each variable in the model appears on the left-hand side of one and only one equation. Variables can be either observed (exist as variables in your dataset) or unobserved. Because the state variables are fixed in the current period, equations for state variables express how the one-step-ahead value of the state variable depends on current state variables and, possibly, current control variables.

Estimating the model parameters gives us an output table:

```
. dsge (x = E(F.x) - (r - E(F.p) - z), unobserved) ///
> (p = {beta}*E(F.p) + {kappa}*x) ///
> (r = 1/{beta}*p + u) ///
> (F.z = {rhoz}*z, state) ///
> (F.u = {rhou}*u, state)
(setting technique to bfgs)
Iteration 0: log likelihood = -13738.863
Iteration 1: log likelihood = -1311.9615 (backed up)
Iteration 2: log likelihood = -1024.7903 (backed up)
Iteration 3: log likelihood = -869.19312 (backed up)
Iteration 4: log likelihood = -841.79194 (backed up)
(switching technique to nr)
Iteration 5: log likelihood = -819.0268 (not concave)
Iteration 6: log likelihood = -782.4525 (not concave)
Iteration 7: log likelihood = -764.07067
Iteration 8: log likelihood = -757.85496
Iteration 9: log likelihood = -754.02921
Iteration 10: log likelihood = -753.58072
Iteration 11: log likelihood = -753.57136
Iteration 12: log likelihood = -753.57131
DSGE model
Sample: 1955q1 - 2015q4 Number of obs = 244
Log likelihood = -753.57131
------------------------------------------------------------------------------
| OIM
| Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
/structural |
beta | .514668 .078349 6.57 0.000 .3611067 .6682292
kappa | .1659046 .047407 3.50 0.000 .0729885 .2588207
rhoz | .9545256 .0186424 51.20 0.000 .9179872 .991064
rhou | .7005492 .0452603 15.48 0.000 .6118406 .7892578
-------------+----------------------------------------------------------------
sd(e.z)| .6211208 .1015081 .4221685 .820073
sd(e.u)| 2.3182 .3047433 1.720914 2.915486
------------------------------------------------------------------------------
```

The crucial parameter is **{kappa}**, which is estimated to be positive. This parameter is related to the underlying price frictions in the model. Its interpretation is that if we hold expected future inflation constant, a 1 percentage point increase in the output gap leads to a **0.17 percentage point increase** in inflation.

The parameter *β* is estimated to be about 0.5, meaning that the coefficient on inflation in the interest rate equation is about 2. So the central bank increases the interest rate about two for one in response to movements in inflation. This parameter is much discussed in the monetary economics literature, and estimates of it cluster around 1.5. The value found here is comparable with those estimates. Both state variables *z~t~* and *u~t~* are estimated to be persistent, with autoregressive coefficients of 0.95 and 0.7, respectively.

We can now use the model to answer questions. One question the model can answer is, **“What is the effect of an unexpected change in the interest rate on inflation and the output gap?”** An unexpected change in the interest rate is modeled as a shock to the ut equation. In the language of the model, this shock represents a contraction in monetary policy.

An impulse is a series of values for the shock *ξ* in (5): (1,0,0,0,0,…). The shock then feeds into the model’s state variables, leading to an increase in *u*. From there, the increase in *u* leads to a change in all the model’s control variables. An impulse–response function traces out the effect of a shock on the model variables, taking into account all the interrelationships among variables present in the model equations.

We type three commands to build and graph an `IRF`

. irf set sets the IRF file that will hold the **impulse–responses**. irf create creates a set of impulse–responses in the IRF file.

```
. irf set dsge_irf. irf create model1
```

With the impulse–responses saved, we can graph them:

```
. irf graph irf, impulse(u) response(x p r u) byopts(yrescale) yline(0)
```

The impulse–response graphs the response of model variables to a one-standard-deviation shock. Each panel is the response of one variable to the shock. The horizontal axis measures time since the shock, and the vertical axis measures deviations from long-run value. The bottom-left panel shows the response of the monetary state variable, *u~t~*.

The remaining three panels show the response of inflation, the interest rate, and the output gap. Inflation is in the top-left panel; it falls on impact of the shock. The interest rate response in the upper-right panel is a weighted sum of the inflation and monetary impulse–responses. The interest rate rises by about one-half of one percentage point. Finally, the output gap falls. Hence, the model predicts that after a monetary tightening, the economy will enter a recession. Over time, the effect of the shock dissipates, and all variables return to their long-run values.

In this post, I developed a small DSGE model and described how to estimate the parameters of the model using **dsge**. I then showed how to create and interpret an impulse–response function.

连享会-直播课上线了！

http://lianxh.duanshu.com

免费公开课：

直击面板数据模型 - 连玉君，时长：1小时40分钟 Stata 33 讲 - 连玉君, 每讲 15 分钟. 部分直播课 课程资料下载 (PPT，dofiles等)

支持回看，所有课程可以随时购买观看。

专题 | 嘉宾 | 直播/回看视频 |
---|---|---|

⭐ 最新专题 ⭐ |
DSGE, 因果推断, 空间计量等 | |

⭕ Stata数据清洗 |
游万海 | 直播, 2 小时，已上线 |

研究设计 | 连玉君 | 我的特斯拉-实证研究设计，-幻灯片- |

面板模型 | 连玉君 | 动态面板模型，-幻灯片- |

面板模型 | 连玉君 | 直击面板数据模型 [免费公开课，2小时] |

Note: 部分课程的资料，PPT 等可以前往 连享会-直播课 主页查看，下载。

## 关于我们

**Stata连享会**由中山大学连玉君老师团队创办，定期分享实证分析经验。直播间 有很多视频课程，可以随时观看。连享会-主页 和 知乎专栏，300+ 推文，实证分析不再抓狂。 **公众号推文分类：**计量专题 | 分类推文 | 资源工具。推文分成**内生性**|**空间计量**|**时序面板**|**结果输出**|**交乘调节**五类，主流方法介绍一目了然：DID, RDD, IV, GMM, FE, Probit 等。**公众号关键词搜索/回复**功能已经上线。大家可以在公众号左下角点击键盘图标，输入简要关键词，以便快速呈现历史推文，获取工具软件和数据下载。常见关键词：`课程, 直播, 视频, 客服, 模型设定, 研究设计, stata, plus, 绘图, 编程, 面板, 论文重现, 可视化, RDD, DID, PSM, 合成控制法`

等

连享会小程序：扫一扫，看推文，看视频……

扫码加入连享会微信群，提问交流更方便

✏ 连享会学习群-常见问题解答汇总：

✨ https://gitee.com/arlionn/WD

12/05
计量专题
9402

10/10
专题课程
8093

12/05
专题课程
2797

12/05
专题课程
1023

01/18
计量专题
54

01/16
面板数据
122

01/13
回归分析
104

01/13
Stata命令
99

01/11
Stata入门
72

01/10
Stata资源
6440