本文主要对聚类调整标准误的原理及其在 Stata 中的具体应用进行简要介绍,包括不同类型的模型中进行「一维聚类调整标准误」和「二维聚类调整标准误」的操作方法。对于该方法更深入的了解,可参考 Petersen (2009)、Thompson (2011)、 Cameron and Miller (2015)、 Abadie et al. (2017) 、Gu and Yoo (2019)等文献。在文章末尾,还对常见的与标准误相关的问题进行了探讨,以便加深对相关内容的理解。
2. 认识标准误
2.1 什么是标准误
为了简便,以仅含有一个非随机解释变量,且不含有截距项回归模型为例予以说明,具体如下:
其中,,。
采用 OLS 方法进行估计,系数的估计量可表示为:
将式 (2) 中的 用式 (1) 替换,整理得:
系数方差的一般形式可以表示为:
若误差项间不相关,则 可以表示为:
进一步,若「同方差」,则 ,式 (4) 可以表示为:
若「异方差」,由于 ,则 ,式 (4) 可以表示为:
White (1980) 认为当 时, 可以由 表示,其中,。
这里 的标准误就是稳健标准误 (robust standard error),更为准确的表述为异方差稳健标准误 (heteroskedastic-robust standard error)。
若误差项间存在自相关,则 可以表示为:
一个直接的想法是对 White (1980) 扩展,采用 替代 ,但是由于 ,使得 也为 0。
对于时间序列数据,假设误差项在间隔 m 期存在自相关和异方差问题,那么 White (1980) 可以扩展产生异方差自相关一致性估计 (heteroskedastic - and autocorrelation-consistent, HAC),详见 Newey and West (1987)。
与上述解决同时存在自相关和异方差问题思路类似,聚类标准误 (cluster errors) 假设样本 i 和 j 不在同一组时,,可得:
进一步,用 替代 ,可得:
其中, 为指示函数。在事件 发生时,等于 ,反之为 。这里 的标准误就是聚类稳健标准误 (cluster-robust standard error)。
系数估计量的标准差和标准误是既有联系又有区别的两个统计量:
系数估计量 的标准差 (standard deviation) 为其方差的平方根:
系数估计量 的标准误 (standard error) 为其方差估计量的平方根:
2.2 标准误的作用
标准误在统计推断中的作用主要有以下两个方面:
构建 t 统计量。在进行统计推断时,需要构建 t 统计量来对单个参数进行假设检验, 所对应的 t 统计量为:
/*
*-截面数据,在公司层面进行聚类,以下两种写法等价
reg y x, cluster(id)
reg y x, vce(cluster id)
*-面板数据,在公司层面进行聚类,以下三种写法等价
xtset id year
xtreg y x, fe cluster(id)
xtreg y x, fe vce(cluster id)
xtreg y x, fe robust // If you specify -xtreg, fe robust-, Stata will automatically, and without even telling you, use vce(cluster panel_variable) instead. (This is true since version 13.)
*/
以 nlswork.dta 为例,对 Stata 相关命令和结果予以说明。
*-调入数据
*copy http://www.stata-press.com/data/r9/nlswork.dta nlswork.dta, replace
use nlswork.dta, clear
*-定义全局暂元
global x "age grade"
*-回归结果
reg ln_wage $x //干扰项同方差
est store m1
reg ln_wage $x, robust //干扰项异方差
est store m2
reg ln_wage $x, vce(cluster idcode)
est store m3
无论对标准误作何处理,该变的只有标准误,系数是不该变。如果发现调整 cluster 对象系数改变,很可能是样本发生改变。如 cluster(id) 和 cluster(industry) 不同的话,和可能是 id 或 industry 存在缺失值。
6. 参考文献
[1] Petersen, M. A. 2009. Estimating Standard Errors in Finance Panel Data Sets: Comparing Approaches. Review of Financial Studies, 22(1): 435-480. [PDF]
[2] Thompson, S. B., 2011, Simple formulas for standard errors that cluster by both firm and time, Journal of Financial Economics, 99 (1): 1-10. [PDF]
[3] Cameron, C. A., D. L. Miller, 2015, A practitioner’s guide to cluster-robust inference, Journal of Human Resources, 50 (2): 317-372. [PDF]
[4] Abadie, A., S. Athey, G. W. Imbens, J. Wooldridge, 2017, When should you adjust standard errors for clustering?, Working Paper. [PDF]
[5] Gu, A. and Yoo, H. I., 2019, Vcemway: A One-Stop Solution for Robust Inference with Multiway Clustering, The Stata Journal, 19(4): pp.900-912. [PDF]