Stata:异方差和自相关稳健F检验和t检验-T316

发布时间:2021-05-08 阅读 7903

Stata连享会   主页 || 视频 || 推文 || 知乎

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

New! lianxh 命令发布了:
随时搜索推文、Stata 资源。安装命令如下:
. ssc install lianxh
详情参见帮助文件 (有惊喜):
. help lianxh

课程详情 https://gitee.com/lianxh/Course

课程主页 https://gitee.com/lianxh/Course

⛳ Stata 系列推文:

PDF下载 - 推文合集

整理人:吴芳倩 (中国人民大学)
邮箱wufangqian704@163.com


目录


1. 引言

异方差自相关一直是计量经济学领域非常重要的问题。在过去的 20 年里,学者们在异方差自相关稳健(HAR)推论方面取得了很大的进展,尤其是发展出了固定平滑渐近理论(Kiefer & Vogelsang,2005; Sun,2014a)。相较于传统递增平滑渐近近似(卡方近似、正态近似),固定平滑渐近近似被证明更为精确(Jansson,2004; Sun, Philips $ Jin,2008)。 但在实证估计中,固定平滑渐近近似却没有被广泛采用。这主要是因为:

  • 基于核方差估计的固定平滑渐近分布是非标准的分布,因此必须模拟临界值;
  • 没有对应的 Stata 命令实现这种近似。

为此,Ye & Sun (2018) 提供了两对新的估计命令和估计后检验命令来解决这一问题。 这两对命令分别为:

  • harhart 命令
  • gmmhargmmhart 命令

本文以 Ye & Sun (2018) 为基础,介绍它们的适用场景、优势和使用方法。相关理论推导和证明参见原文:

Xiaoqing Ye, Yixiao Sun, 2018, Heteroskedasticity- and Autocorrelation-robust F and t Tests in Stata, Stata Journal, 18(4): 951–980. -PDF-, -PDF2-

原文摘要. 在这篇文章中,我们考虑了时间序列、OLS 和 IV 回归,介绍了一对新的命令:harhart。它们紧跟学界在 HAR 推论上的最新进展——使用更精确的异方差自相关稳健(HAR)的 F 和 t 检验。 F 和 t 检验以简单的 F 和 t 近似为基础,而这两个近似比传统的正态近似和卡方近似更为准确。这对命令背后关于平滑参数的选取,也充分考虑到了假设检验问题的两类错误。并且,在使用估计命令 har 和估计后检验命令 hart 时,既可以选择核 HAR 方差估计量,也可以选择正交序列 HAR 方差估计量。此外,文章还介绍了另一对新命令:gmmhargmmhart。它们实现了两步 GMM 框架下的 F 和 t 检验。在用这对命令时,我们选择正交序列 HAR 方差估计量,因为在第一步 GMM 下,F 近似和 t 近似极易实施。最后,我们用一些例子来说明这些命令的使用。

Abstract. In this article, we consider time-series, ordinary least-squares, and instrumental-variable regressions and introduce a new pair of commands, har and hart, that implement more accurate heteroskedasticity-and autocorrelationrobust (HAR) F and t tests. These tests represent part of the recent progress on HAR inference. The F and t tests are based on the convenient F and t approximations and are more accurate than the conventional chi-squared and normal approximations. The underlying smoothing parameters are selected to target the type I and type II errors, which are the two fundamental objects in every hypothesis testing problem. The estimation command har and the postestimation test command hart allow for both kernel HAR variance estimators and orthonormalseries HAR variance estimators. In addition, we introduce another pair of new commands, gmmhar and gmmhart, that implement the recently developed F and t tests in a two-step generalized method of moments framework. For these commands, we opt for the orthonormal-series HAR variance estimator based on the Fourier bases because it allows us to develop convenient F and t approximations as in the first-step generalized method of moments framework. Finally, we present several examples to demonstrate these commands.


2. 适用场景及优势

2.1 适用场景

今天介绍的命令以固定平滑渐近理论为基础,适用于对时间序列数据、线性回归模型进行 OLS 或 IV 估计。

2.2 优势

相较于以往的 Stata 命令,今天要介绍的命令至少具备如下优势:

(1) harhart

  • 实现了对可能具有内生协变量的线性回归模型的固定平滑 Wald 和 t 检验。对于单一约束的情况,newey 使用标准正态近似,而 har 使用 t 近似。对于有多个约束的联合检验,neweytest 使用卡方近似,而 harhart 使用 F 近似;
  • 在平滑参数选取上, harhart 基于最小化损失函数的原则,对不同的检验使用不同的最佳平滑参数。而 neweytest 对所有检验使用单一的平滑参数;
  • har 基于固定平滑近似来构造置信区间,而以往命令 newey 基于传统正态近似来构造置信区间。当一阶自相关系数为 0.75 时,前者对应的置信区间依然非常准确,但后者对应的置信区间准确度严重恶化。

(2) gmmhargmmhart

  • 在两步有效 GMM 框架下,实现了固定平滑 Wald 和 t 检验;
  • 在两步 GMM 中,由 gmmhargmmhart 得到的 HAR 方差估计量不仅出现在协方差估计量中,而且在第二步的 GMM 准则函数中起到最优加权矩阵的作用;
  • 新的估计命令 gmmhar 基于固定平滑近似来构造置信区间,而以往估计命令 ivregress gmm 基于传统正态近似来构造置信区间。当工具变量数量增大时,由以往命令得到的置信区间精度严重恶化,而由新的估计命令得到的置信区间仍保持良好的精确性。

3. 安装命令

harhart 命令配对出现,前者用于估计模型,后者用于检验;gmmhargmmhart 命令的关系亦是如此。

在 Stata 命令窗口中输入如下命令,即可打开安装页面,按提示点击相应按钮即可:

. net describe st0548, from(http://www.stata-journal.com/software/sj18-4)

当然,我们也可以直接执行如下命令直接安装上述文件:

. net install st0548.pkg  // 安装程序文件
. net get     st0548.pkg  // 下载相关附件到当前工作路径下

完成安装后,输入 help har 即可查看 har 命令的帮助文件。其它三个命令的帮助文件也可以采用这种方式获取。

4. 估计命令介绍

hargmmhar 的语法结构如下:

har depvar [varlist1] (varlist2 = varlist_iv) [if] [in] , ///
    kernel(string) [noconstant level(#)]
gmmhar depvar [varlist1] (varlist2 = varlist_iv) [if] [in] ///
    [ , noconstant level(#)]

部分输入项的解释如下:

  • depvar:被解释变量;
  • varlist2:内生解释变量;
  • varlist_iv:varlist2 的工具变量;
  • kernel(string);必需,设置核函数 (kernel) 的类型,详情参见 Ye & Sun (2018):
    • 对于 Bartlett kernel,可以使用 kernel(bartlett), kernel(BARTLETT), kernel(B) 或 kernel(b)
    • 对于 Parzen, QS, 和 OS LRV estimators, 可以使用 (PARZEN, parzen, P, p), (QUADRATIC, quadratic, Q, q) 或 (ORTHOSERIES, orthoseries, O, o)
  • nonconstant:略去截距项估计;
  • level(#):设置置信区间的置信水平 (默认 95%) 。

5. 估计后的检验命令介绍

这部分介绍 hartgmmhart 两个估计后的检验命令。这两个命令需分别于 hargmmhar 命令后立刻执行。它们利用 Wald 检验,但使用了更准确的固定平滑临界值。

检验系数联合为 0:

hart coeflist, kernel(string) [accumulate level(#)]
gmmhart coeflist [, accumulate]

检验一个或多个线性约束:

hart exp = exp [= ...], kernel(string) [accumulate level(#)]
gmmhart exp = exp [= ...] [, accumulate]

6. Stata 实例

6.1 har + hart

下面我们用一个公开的时间序列数据来操作此对命令。数据来源:http://www.stata-press.com/data/r15/idle2.dta

  • Nonparametric Bartlett kernel approach,default confidence level 95%,testing- optimal automatic bandwidth selection:
. webuse idle2, clear
. tsset time

. har usr idle wio, kernel(bartlett)
Regression with HAR standard errors             Number of obs =      30
Kernel: Bartlett                                F(  2,    17) =   47.66
Data-driven optimal lag: 2                      Prob > F      =  0.0000
-----------------------------------------------------------------------
   usr |   Coef.   HAR Std. Err.  t    df  P>|t|   [95% Conf. Interval]
-------+---------------------------------------------------------------
  idle | -.6670978   .0715786   -9.32  22  0.000  -.8155428  -.5186529
   wio | -.7792461     .11897   -6.55  13  0.000  -1.036265   -.522227
 _cons |  66.21805   6.984346    9.48  19  0.000   51.59965   80.83646
-----------------------------------------------------------------------

. hart idle=wio=0, kernel(bartlett)
       F(  2,    17) =   47.6645
           Prob > F  =    0.0000

. quietly hart idle=0, kernel(bartlett)
. hart idle=wio, kernel(bartlett) acc
       F(  2,    17) =   47.6645
           Prob > F  =    0.0000

. hart 1.168*idle=wio, kernel(bartlett)
       F(  1,    14) =    0.0000
           Prob > F  =    0.9989

估计结果显示:变量 idlewio 都显著影响 usr。后估计检验结果显示: (1) 前两个命令检验 idlewio 前的系数是否都为零。 F 检验结果拒绝原假设。 (2) 最后一个命令检验 wio 前系数等于 idle 前系数的 1.168 倍。 F 检验结果不能拒绝原假设。

6.2 gmmhar + gmmhart

下面我们用一个季度时间序列模型来说明这一对命令的使用。该模型将 1959 年第一季度至 2000 年第四季度美国通胀率的变化与失业率联系起来。我们使用季度 GDP 增长的滞后二期,国债利率、贸易加权汇率和国债中期利率的滞后一期作为工具变量,采用两步有效 GMM 方法进行模型估计。

  • Nonparametric OS approach, confidence level 95%, AMSE automatic bandwidth selection:
. use http://fmwww.bc.edu/ec-p/data/stockwatson/macrodat, clear
. generate inf =100 * log( CPI / L4.CPI )
(4 missing values generated)
. generate ggdp=100 * log( GDP / L4.GDP )
(10 missing values generated)
. gmmhar D.inf (UR=L2.ggdp L.TBILL L.ER L.TBON)
Two-step Efficient GMM Estimation               Number of obs =     158
Data-driven optimal K: 46                       F(  1,    43) =    2.05
                                                Prob > F      =  0.1597
-----------------------------------------------------------------------
 D.inf |   Coef.   HAR Std. Err.  t    df  P>|t|   [95% Conf. Interval]
-------+---------------------------------------------------------------
    UR | -.0971458    .067901   -1.43  43  0.160  -.2340812   .0397895
 _cons |  .5631061   .3936908    1.43  43  0.160  -.2308471   1.357059
-----------------------------------------------------------------------
HAR J statistic = .92614349
Reference Dist for the J test: F( 3,  44)
P-value of the J test =  0.4361
Instrumented: UR
Instruments: L2.ggdp L.TBILL L.ER L.TBON
. gmmhart UR=0
(10 missing values generated)
       F(  1,    43) =    2.05
            Prob > F =    0.1597
. gmmhart UR   // a shorter command of “gmmhart UR=0”
(10 missing values generated)
       F(  1,    43) =    2.05
            Prob > F =    0.1597
. gmmhart UR=-0.09715
(10 missing values generated)
       F(  1,    43) =    0.00
            Prob > F =    1.0000

估计结果显示:失业率 (UR) 系数显著为负,这与基本宏观经济理论一致:将失业率降至自然失业率以下将导致价格通胀加速。固定平滑 J 检验结果接受零假设,证明了工具变量选取的合理性。后估计检验结果显示: (1) UR 系数显著不为 0; (2) UR 系数显著不为 -0.09715。


7. 总结

本文主要介绍了两对命令:

  • hargmmhar
  • hartgmmhart

由于在固定平滑渐近性下,修正的 Wald 统计量是渐近 F 分布的,修正的 t 统计量是渐近 t 分布的 (Hwang & Sun,2017),用于检验过度识别的 J 统计量也是渐进 F 分布的 (Sun & Kim,2012) 。因此,这两对命令具有很强的适用性。

总之,在对于含有时间序列的 OLS 和 IV 估计中,相较于以往的 Stata 命令,本文介绍的命令提供了更准确的置信区间,增强了假设检验的可信度。


8. 参考文献

  • Hwang J, Sun Y. Asymptotic F and t Tests in an Efficient GMM Setting[J]. Journal of Econometrics, 2017, 198(2): 277-295. -PDF-, -PDF2-
  • Jansson M. The error in rejection probability of simple autocorrelation robust tests[J]. Econometrica, 2004, 72(3): 937-946. -PDF-, -PDF2-
  • Kiefer N M, Vogelsang T J. A new asymptotic theory for heteroskedasticity-autocorrelation robust tests[J]. Econometric Theory, 2005: 1130-1164.-PDF-, -PDF2-
  • Sun Y. Let’s fix it: Fixed-b asymptotics versus small-b asymptotics in heteroskedasticity and autocorrelation robust inference[J]. Journal of Econometrics, 2014, 178: 659-677.-PDF-, -PDF2-
  • Sun Y, Kim M S. Simple and powerful GMM over-identification tests with accurate size[J]. Journal of Econometrics, 2012, 166(2): 267-281. -PDF-, -PDF2-
  • Sun Y, Phillips P C B, Jin S. Optimal bandwidth selection in heteroskedasticity–autocorrelation robust testing[J]. Econometrica, 2008, 76(1): 175-194.-PDF-, -PDF2-
  • Xiaoqing Ye, Yixiao Sun, 2018, Heteroskedasticity- and Autocorrelation-robust F and t Tests in Stata, Stata Journal, 18(4): 951–980. -PDF-, -PDF2-

相关课程

免费公开课

最新课程-直播课

专题 嘉宾 直播/回看视频
最新专题 文本分析、机器学习、效率专题、生存分析等
研究设计 连玉君 我的特斯拉-实证研究设计-幻灯片-
面板模型 连玉君 动态面板模型-幻灯片-
面板模型 连玉君 直击面板数据模型 [免费公开课,2小时]
  • Note: 部分课程的资料,PPT 等可以前往 连享会-直播课 主页查看,下载。

课程主页

课程主页

关于我们

  • Stata连享会 由中山大学连玉君老师团队创办,定期分享实证分析经验。
  • 连享会-主页知乎专栏,400+ 推文,实证分析不再抓狂。直播间 有很多视频课程,可以随时观看。
  • 公众号关键词搜索/回复 功能已经上线。大家可以在公众号左下角点击键盘图标,输入简要关键词,以便快速呈现历史推文,获取工具软件和数据下载。常见关键词:课程, 直播, 视频, 客服, 模型设定, 研究设计, stata, plus, 绘图, 编程, 面板, 论文重现, 可视化, RDD, DID, PSM, 合成控制法

连享会小程序:扫一扫,看推文,看视频……

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

✏ 连享会-常见问题解答:
https://gitee.com/lianxh/Course/wikis

New! lianxh 命令发布了:
随时搜索连享会推文、Stata 资源,安装命令如下:
. ssc install lianxh
使用详情参见帮助文件 (有惊喜):
. help lianxh