Stata连享会 主页 || 视频 || 推文 || 知乎 || Bilibili 站
温馨提示: 定期 清理浏览器缓存,可以获得最佳浏览体验。
New!
lianxh
命令发布了:
随时搜索推文、Stata 资源。安装:
. ssc install lianxh
详情参见帮助文件 (有惊喜):
. help lianxh
连享会新命令:cnssc
,ihelp
,rdbalance
,gitee
,installpkg
⛳ Stata 系列推文:
作者:彭甲超 (中国地质大学)
邮箱:pengjiachao@cug.edu.cn
编者按:本文主要摘译自下文,特此致谢!
Source:Yan G, Chen Q. RCM: Stata module to implement regression control method/panel data approach to program evaluation[J]. 2021. -Link- -Slide- -Video-
目录
回归控制法 (Regression Control Method,rcm) 由 Hsiao 等 (2012) 提出。该方法利用横截面相关性,通过线性回归 (OLS)、Lasso 或 Post-Lasso-OLS 构建处理单元的反事实结果,是近年来流行的一种因果推断方法,尤其适用于面板数据中只有一个或几个处理个体或地区的情形。
具体而言,rcm 法认为经济中存在一些不可观测的 “共同因子” 影响个体,使得不同个体之间存在截面相关性。rcm
命令是首个在 Stata 中实现回归控制法的命令 (Yan 和 Chen,2021),能够实现通过线性回归 (OLS)、Lasso 或 Post-Lasso-OLS 来构建处理单元的反事实结果预测和因果推断。
本节参考方诚和陈强 (2021)的相关内容论述 rcm
理论模型。
假定观测到的面板数据为
记
可观测的结果变量
其中
其中
其中
其中
在政策实施前的区段,如果方程 (4) 的 OLS 回归拟合效果好,则此模型预测个体
在用政策实施前的数据估计方程 (4) 时,还需选择放入此方程的控制组个体数。放入越多的控制组个体,则方程 (4) 的解释变量越多,虽可得到更高的
为此,需要使用信息准则来惩罚过于复杂 (解释变量过多) 的模型,以选择解释变量的 “最优子集”,保证样本外 (即政策实施后) 的预测效果。Hsiao 等 (2012) 建议使用 AIC 与 AICC 来选择最优子集,而 Li 和 Bell (2017) 则建议使用 Lasso 估计量筛选变量,然后再进行OLS回归,即所谓 Post-Lasso-OLS。
假定选择控制组的
其中
* 命令安装
ssc install rcm, all replace
* 命令语法
rcm depvar [indepvars] [if] [in], trunit(#) trperiod(#) [options]
其中,
depvar
和 indepvars
必须是数值变量,不允许使用缩写。同时必须使用 xtset panelvar timevar
来声明面板数据集;trunit(#)
指定被处理单元 (即受干预影响的单元) 的单元号。注意,只能指定单个受影响的单元;trperoid(#)
干预发生的时间周期,必须是一个整数。注意,只能指定一个时间段。options
如下:
(1) Model
ctrlunit(numlist)
:表示控制单元;preperiod(numlist)
:表示受干预前;postperiod(numlist)
:表示受干预后。(2) Optimization:模型选择包括 rcm
自动执行的两个步骤:
rcm
选择一系列次优模型,每个模型包含一个唯一的预测子集。选择次优模型的具体步骤取决于 method(sel_method)
指定的选择方法。现有的选择方法有:最优子集、Lasso 估计量、前向分步法或后向分步法;rcm
通过信息准则或由准则 (sel_criterion)
指定的交叉验证从次优模型中选择最优模型。允许的 sel_criteria
包括信息准则或 K 折交叉验证 (K-fold Cross-Validation) 选择变量。默认情况下,在选择最佳模型时对预测器的数量没有限制,但是可以通过范围 (p_min p_max)
指定允许的预测器数量,以限制其范围。(3) Placebo Test
placebo([unit unit(numlist) period(numlist) cutoff(#_c)])
:指定要进行安慰剂试验的类型,否则不进行安慰剂试验。(4) Reporting
frame(framename)
:创建一个 Stata 数据框,以宽格式存储数据集和生成的变量;nofigure
:不要显示图,默认是显示所有的图。
. ssc install rcm, all replace // 获取数据
. use growth, clear
. xtset region time
* Show the unit number of Hong Kong and treatment periods
. label list
. display tq(1997q3)
. display tq(2003q4)
OLS 估计通常报告步骤 1 和步骤 2 相应结果,最后给出反事实的对比。
. /*
> Replicate results in Hsiao et al.(2012) with specified control units
> and designated post-treatment periods
> */
. rcm gdp, trunit(9) trperiod(150) ctrlunit(4 10 12 13 14 19 20 22 23 25) ///
> postperiod(150/175)
Step 1: Select the suboptimal models
Step 2: Select the optimal model from the suboptimal models
Comparing the suboptimal models containing different set of predictors:
-----------------------------------------------------------------
K | AICc AIC BIC MBIC R-squared
----+------------------------------------------------------------
1 | -144.7514 -146.4657 -143.7946 -155.6437 0.4034
2 | -160.5063 -163.5832 -160.0217 -170.4959 0.7937
3 | -170.6492 -175.6492 -171.1973 -180.9287 0.9056
4 | -171.7725 -179.4088 -174.0666 -183.1559 0.9314
(omitted)
10 | -111.3603 -173.7603 -163.0758 -167.4256 0.9518
-----------------------------------------------------------------
Among models with 1-10 predictors, the optimal model contains 4 predictors
with AICc = -171.7725.
Fitting results in the pre-treatment periods using OLS:
----------------------------------------------------------------------------------
gdp·HongKong | Coefficient Std. err. t P>|t| [95% conf. interval]
-----------------+----------------------------------------------------------------
gdp·Korea | -0.4323 0.0634 -6.82 0.000 -0.5692 -0.2954
gdp·Japan | -0.6760 0.1117 -6.05 0.000 -0.9172 -0.4347
gdp·Taiwan | 0.7926 0.3099 2.56 0.024 0.1231 1.4621
gdp·UnitedStates | 0.4860 0.2195 2.21 0.045 0.0118 0.9603
_cons | 0.0263 0.0170 1.54 0.147 -0.0105 0.0631
----------------------------------------------------------------------------------
Prediction results in the post-treatment periods using OLS:
-------------------------------------------------------------
Time | Actual Outcome Predicted Outcome Treatment Effect
--------+----------------------------------------------------
1997q3 | 0.0610 0.0798 -0.0188
1997q4 | 0.0140 0.0810 -0.0670
(omitted)
2003q3 | 0.0380 0.0628 -0.0248
2003q4 | 0.0470 0.0761 -0.0291
--------+----------------------------------------------------
Mean | 0.0180 0.0576 -0.0396
-------------------------------------------------------------
Note: The average treatment effect over the post-treatment periods is -0.0396.
rcm
还具有完善的画图功能。OLS 估计给出的反事实分析结果和处理效应,分别如下图所示。
此回归方程具有较好的拟合效果,在政策实施前 (图中的虚线左侧),反事实预测值与的实际观测值十分接近,这表明控制组可以很好地反映 GDP 走势,甚至拐点部分也能较好地拟合。更重要的,从政策冲击开始之后 (图中虚线右侧),反事实预测值与实际观测值开始日益背离,并随时间的大幅波动,这说明政策对 GDP 影响较为显著。
将实际观测值减去反事实预测值,可得政策效应变化。从处理效应结果可知,政策实施后,与控制组相比,其效应越来越显著。另一方面,与反事实预测的大起大落相比,实际 GDP 明显更为稳定,方差更小,符合政策目标。
与 OLS 估计汇报步骤一致,Post-Lasso 估计同样报告了步骤 1 和步骤 2 的相关结果。不同的是,Post-Lasso OLS 通过惩罚回归来避免过拟合,其最小化的目标函数为:
其中
. /*
> Use post-lasso OLS with LOOCV and all control units,
> and create a Stata frame "growth_wide" storing dataset
> with generated variables in wide form
> */
. rcm gdp, trunit(9) trperiod(150) postperiod(150/175) method(lasso) ///
> criterion(cv) frame(growth_wide)
Step 1: Select the suboptimal models
Step 2: Select the optimal model from the suboptimal models
Comparing the suboptimal models containing different set of predictors:
-------------------------------------------------------------------------
K | lambda CVMSE R-squared | Operation
----+------------------------------------+-------------------------------
1 | 0.0136 0.0004 0.0513 | add gdp·Mexico
(omitted)
12 | 0.0002 0.0001 0.9782 | drop gdp·Canada
13 | 0.0002 0.0001 0.9795 | add gdp·UnitedKingdom
12 | 0.0002 0.0001 0.9822 | drop gdp·UnitedStates
12 | 0.0001 0.0001 0.9876 | .
-------------------------------------------------------------------------
Among models with 1-24 predictors, the optimal model contains 12 predictors
with CVMSE = 0.0001.
Fitting results in the pre-treatment periods using post-lasso OLS:
-----------------------------------------------------------------------------------
gdp·HongKong | Coefficient Std. err. t P>|t| [95% conf. interval]
------------------+----------------------------------------------------------------
gdp·Australia | 0.0293 0.0988 0.30 0.779 -0.2247 0.2833
gdp·China | 0.3318 0.1115 2.98 0.031 0.0452 0.6184
gdp·France | 0.4306 0.1858 2.32 0.068 -0.0469 0.9081
gdp·Germany | 0.5107 0.1917 2.66 0.045 0.0180 1.0033
gdp·Japan | -0.8833 0.1007 -8.77 0.000 -1.1421 -0.6244
gdp·Korea | -0.6836 0.0753 -9.07 0.000 -0.8773 -0.4900
gdp·Malaysia | 0.0400 0.0481 0.83 0.443 -0.0836 0.1636
gdp·Mexico | 0.0667 0.0489 1.36 0.231 -0.0591 0.1925
gdp·Philippines | -0.6231 0.1339 -4.65 0.006 -0.9674 -0.2789
gdp·Switzerland | 0.1001 0.1098 0.91 0.404 -0.1822 0.3824
gdp·Taiwan | -0.4112 0.4313 -0.95 0.384 -1.5198 0.6974
gdp·UnitedKingdom | 0.8364 0.2854 2.93 0.033 0.1027 1.5701
_cons | 0.0881 0.0220 4.01 0.010 0.0317 0.1446
-----------------------------------------------------------------------------------
Prediction results in the post-treatment periods using post-lasso OLS:
-------------------------------------------------------------
Time | Actual Outcome Predicted Outcome Treatment Effect
--------+----------------------------------------------------
1997q3 | 0.0610 0.0896 -0.0286
1997q4 | 0.0140 0.0929 -0.0789
(omitted)
2003q3 | 0.0380 0.0829 -0.0449
2003q4 | 0.0470 0.0950 -0.0480
--------+----------------------------------------------------
Mean | 0.0180 0.1055 -0.0875
-------------------------------------------------------------
Note: The average treatment effect over the post-treatment periods is -0.0875.
. * Implement a placebo test using all fake treatment units in the donor pool
. rcm gdp, trunit(9) trperiod(150) postperiod(150/175) method(lasso) ///
> criterion(cv) placebo(unit)
Step 1: Select the suboptimal models
Step 2: Select the optimal model from the suboptimal models
Comparing the suboptimal models containing different set of predictors:
-------------------------------------------------------------------------
K | lambda CVMSE R-squared | Operation
----+------------------------------------+-------------------------------
1 | 0.0136 0.0004 0.0513 | add gdp·Mexico
(omitted)
12 | 0.0002 0.0001 0.9782 | drop gdp·Canada
13 | 0.0002 0.0001 0.9795 | add gdp·UnitedKingdom
12 | 0.0002 0.0001 0.9822 | drop gdp·UnitedStates
12 | 0.0001 0.0001 0.9876 | .
-------------------------------------------------------------------------
Among models with 1-24 predictors, the optimal model contains 12 predictors
with CVMSE = 0.0001.
Fitting results in the pre-treatment periods using post-lasso OLS:
-----------------------------------------------------------------------------------
gdp·HongKong | Coefficient Std. err. t P>|t| [95% conf. interval]
------------------+----------------------------------------------------------------
gdp·Australia | 0.0293 0.0988 0.30 0.779 -0.2247 0.2833
(omitted)
gdp·Taiwan | -0.4112 0.4313 -0.95 0.384 -1.5198 0.6974
gdp·UnitedKingdom | 0.8364 0.2854 2.93 0.033 0.1027 1.5701
_cons | 0.0881 0.0220 4.01 0.010 0.0317 0.1446
-----------------------------------------------------------------------------------
Prediction results in the post-treatment periods using post-lasso OLS:
-------------------------------------------------------------
Time | Actual Outcome Predicted Outcome Treatment Effect
--------+----------------------------------------------------
1997q3 | 0.0610 0.0896 -0.0286
1997q4 | 0.0140 0.0929 -0.0789
(omitted)
2003q3 | 0.0380 0.0829 -0.0449
2003q4 | 0.0470 0.0950 -0.0480
--------+----------------------------------------------------
Mean | 0.0180 0.1055 -0.0875
-------------------------------------------------------------
Note: The average treatment effect over the post-treatment periods is -0.0875.
Placebo test results using fake treatment units:
-------------------------------------------------------------------------------
Unit | Pre MSPE Post MSPE Post/Pre MSPE Pre MSPE of Fake Unit/
| Pre MSPE of Treated Unit
---------------+---------------------------------------------------------------
HongKong | 0.0000 0.0198 3009.7824 1.0000
Australia | 0.0000 0.0008 18.5015 6.4202
(omitted)
UnitedKingdom | 0.0000 0.0015 161.0820 1.4022
UnitedStates | 0.0000 0.0001 285.1185 0.0517
-------------------------------------------------------------------------------
Note: The probability of obtaining a post/pre-treatment MSPE ratio as large
as HongKong's is 0.1200.
Placebo test results using fake treatment units (continued):
------------------------------------------------------------------
Time | Treatment Effect p-value of Treatment Effect
| Two-sided Right-sided Left-sided
--------+---------------------------------------------------------
1997q3 | -0.0286 0.2000 0.8800 0.1600
1997q4 | -0.0789 0.0400 1.0000 0.0400
(omitted)
2003q3 | -0.0449 0.1600 0.8800 0.1600
2003q4 | -0.0480 0.1200 0.9200 0.1200
------------------------------------------------------------------
rcm
命令给出了 “虚假处理个体” 或 “虚假处理时间”的安慰剂检验,部分图示如下:
Note:产生如下推文列表的 Stata 命令为:
lianxh aic lasso, m
安装最新版lianxh
命令:
ssc install lianxh, replace
免费公开课
最新课程-直播课
专题 | 嘉宾 | 直播/回看视频 |
---|---|---|
⭐ 最新专题 | 文本分析、机器学习、效率专题、生存分析等 | |
研究设计 | 连玉君 | 我的特斯拉-实证研究设计,-幻灯片- |
面板模型 | 连玉君 | 动态面板模型,-幻灯片- |
面板模型 | 连玉君 | 直击面板数据模型 [免费公开课,2小时] |
⛳ 课程主页
⛳ 课程主页
关于我们
课程, 直播, 视频, 客服, 模型设定, 研究设计, stata, plus, 绘图, 编程, 面板, 论文重现, 可视化, RDD, DID, PSM, 合成控制法
等
连享会小程序:扫一扫,看推文,看视频……
扫码加入连享会微信群,提问交流更方便
✏ 连享会-常见问题解答:
✨ https://gitee.com/lianxh/Course/wikis
New!
lianxh
命令发布了:
随时搜索连享会推文、Stata 资源,安装命令如下:
. ssc install lianxh
使用详情参见帮助文件 (有惊喜):
. help lianxh