DID前沿_DID模型时间、空间、混合安慰剂检验新命令didplacebo
1、简介
DID安慰剂检验的Stata新命令didplacebo,可以自动进行DID模型的时间、空间及时空混合安慰剂检验,并提供可视化展示。
didplacebo实现了用于估计差异中的差异(DID)模型的安慰剂检验,其中政策采用可能是同步的或交错的。特别是,didplacebo使用假的治疗时间进行时间安慰剂检验,使用假的处理单位(随机选择)进行空间安慰剂检验,以及使用假的处理单位和时间(都是随机选择)进行混合安慰剂测试。此外,didplacebo为可视化提供了方便的图表。
要执行安慰剂检验,必须指定估计名称estimatename和处理变量名称treatvarname,作为didplacebo命令的输入。didplacebo自动执行estimatename来获取用于DID估计的命令(cmdline)。然后用相同的命令再次估计模型,使用假的处理变量来产生安慰剂效应。Treatvar (treatvarname)指定一个虚拟变量,指示一个单元在特定时期是否被处理。
除了传统的双向固定效应估计(TWFE)之外,要使用异质性稳健估计(例如,Callaway和Sant'Anna, 2021)进行安慰剂检验,可以使用我们的命令xtshuffle, xtrantreat和tofirsttreat。有关详细说明,请参阅Chen, Qi和Yan(2023)。
didplacebo已被确认与官方命令regress、xtreg、areg和xtdidreress以及第三方命令reghdfe兼容。其他命令虽然没有经过专门测试,但也可能与didplacebo兼容。
2、语法格式
didplacebo estimatename , treatvar(treatvarname) [options]
选项含义:
- frame(framename)存储估计安慰剂的数据框结果
- Savegraph(前缀,[asis replace])将生成的所有图形保存到当前路径。
注意事项:
- 必须使用Xtset panelvar timevar来声明面板数据集,参考[XT] xtset。
- Estimatename应该是由估计存储保存的估计;参考[R] estimate储存
3、 案例应用
3.1 案例1:标准DID: Cao and Chen:2022
1、导入数据
use cao_chen.dta, clear
2、进行TWFE模型估计
. xtset county year
panel variable: county (strongly balanced)
time variable: year, 1650 to 1911
delta: 1 unit
. reghdfe rebel canal_post, absorb(i.county i.year) cluster(county)
(MWFE estimator converged in 2 iterations)
HDFE Linear regression Number of obs = 140,432
Absorbing 2 HDFE groups F( 1, 535) = 5.23
Statistics robust to heteroskedasticity Prob > F = 0.0226
R-squared = 0.0308
Adj R-squared = 0.0253
Within R-sq. = 0.0002
Number of clusters (county) = 536 Root MSE = 0.3848
(Std. Err. adjusted for 536 clusters in county)
------------------------------------------------------------------------------
| Robust
rebel | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
canal_post | .0380143 .016621 2.29 0.023 .0053639 .0706647
_cons | .0313251 .0007227 43.35 0.000 .0299054 .0327447
------------------------------------------------------------------------------
Absorbed degrees of freedom:
-----------------------------------------------------+
Absorbed FE | Categories - Redundant = Num. Coefs |
-------------+---------------------------------------|
county | 536 536 0 *|
year | 262 0 262 |
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation
. estimates store did_cao_chen
.
end of do-file
结论
- 漕粮海运导致运河县的叛乱显著增加,DID系数为 0.038, 且在 5% 水平上显著
3、时间安慰剂检验
结论:安慰剂效应的 p 值均大于 0.1,95% 区间均包括 0,故认为满足平行趋势
4、空间安慰剂检验
5、混合安慰剂检验
. didplacebo did_cao_chen, treatvar(canal_post) pbomix(1)
Implementing mixed placebo test for standard DID (version 1) using both fake treatment units
> and times:
-------------------------------------------------------------------------
The number of units randomly | The range within which fake
selected as fake treatment units | treatment times are randomly selected
----------------------------------+--------------------------------------
73 | [1650, 1911]
-------------------------------------------------------------------------
Simulations (500):.........10.........20.........30.........40.........50.........60........
> .70.........80.........90.........100.........110.........120.........130.........140.....
> ....150.........160.........170.........180.........190.........200.........210.........22
> 0.........230.........240.........250.........260.........270.........280.........290.....
> ....300.........310.........320.........330.........340.........350.........360.........37
> 0.........380.........390.........400.........410.........420.........430.........440.....
> ....450.........460.........470.........480.........490.........500
Results of mixed placebo test for standard DID (version 1) using both fake treatment units a
> nd times:
--------------------------------------------------------------
| | P-value
| Coefficient | Two-sided Left-sided right-sided
-----------+-------------+------------------------------------
canal_post | 0.038014 | 0.0100 0.9960 0.0040
--------------------------------------------------------------
Note: (1) The two-sided p-value is the frequency that the absolute values of the placebo
effects are greater than or equal to the absolute value of estimated treatment
effect.
(2) The left-sided (right-sided) p-value is the frequency that the placebo effects
are smaller (greater) than or equal to the estimated treatment effect.
Finished.
.
处理效应估计值位于安慰剂效应分布的右侧尾部
3.2 案例2:银行管制与收入不平等案例
1、导入数据
use bbb.dta,clear
2、DID模型估计
. xtset statefip wrkyr
panel variable: statefip (strongly balanced)
time variable: wrkyr, 1976 to 2006
delta: 1 unit
. global cov gsp_pc_growth prop_blacks prop_dropouts prop_female_headed unemploymentr
> ate
. xtreg log_gini _intra $cov i.wrkyr, fe r
Fixed-effects (within) regression Number of obs = 1,519
Group variable: statefip Number of groups = 49
R-sq: Obs per group:
within = 0.3876 min = 31
between = 0.0396 avg = 31.0
overall = 0.2339 max = 31
F(36,48) = 98.01
corr(u_i, Xb) = -0.2892 Prob > F = 0.0000
(Std. Err. adjusted for 49 clusters in statefip)
------------------------------------------------------------------------------------
| Robust
log_gini | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------------+----------------------------------------------------------------
_intra | -.0177239 .0064033 -2.77 0.008 -.0305986 -.0048493
gsp_pc_growth | -.0288419 .0412498 -0.70 0.488 -.1117802 .0540965
prop_blacks | -.2128497 .1584963 -1.34 0.186 -.5315277 .1058284
prop_dropouts | .1641627 .0713148 2.30 0.026 .0207748 .3075507
prop_female_headed | .0190403 .056497 0.34 0.738 -.0945545 .1326352
unemploymentrate | .0063327 .0012649 5.01 0.000 .0037895 .0088759
|
wrkyr |
1977 | .0076353 .0068442 1.12 0.270 -.0061259 .0213964
1978 | .0630635 .0072286 8.72 0.000 .0485295 .0775976
1979 | .0892775 .0090404 9.88 0.000 .0711006 .1074543
1980 | .0661498 .0099681 6.64 0.000 .0461077 .0861919
1981 | .0805363 .0099324 8.11 0.000 .0605659 .1005067
1982 | .1508562 .0123343 12.23 0.000 .1260565 .1756559
1983 | .0835548 .0121092 6.90 0.000 .0592076 .1079021
1984 | .0920258 .0130212 7.07 0.000 .065845 .1182066
1985 | .0901488 .0121423 7.42 0.000 .0657351 .1145626
1986 | .0947377 .0127701 7.42 0.000 .0690616 .1204138
1987 | .0852106 .0132274 6.44 0.000 .0586152 .1118061
1988 | .0803313 .0140429 5.72 0.000 .0520961 .1085664
1989 | .0898124 .0152262 5.90 0.000 .0591981 .1204267
1990 | .0771691 .015829 4.88 0.000 .0453429 .1089954
1991 | .0734357 .0170896 4.30 0.000 .0390747 .1077966
1992 | .0781385 .018361 4.26 0.000 .0412212 .1150558
1993 | .0873723 .0196049 4.46 0.000 .047954 .1267905
1994 | .0905129 .0200469 4.52 0.000 .0502059 .1308199
1995 | .1251676 .0205097 6.10 0.000 .0839301 .1664052
1996 | .1072482 .0232226 4.62 0.000 .060556 .1539403
1997 | .1224012 .0223157 5.48 0.000 .0775325 .1672699
1998 | .1099866 .0224811 4.89 0.000 .0647853 .1551878
1999 | .1060401 .0243267 4.36 0.000 .0571279 .1549522
2000 | .1332583 .0248512 5.36 0.000 .0832915 .183225
2001 | .1175197 .0254826 4.61 0.000 .0662835 .1687559
2002 | .1116299 .0262021 4.26 0.000 .0589471 .1643127
2003 | .1192856 .0273775 4.36 0.000 .0642394 .1743319
2004 | .1139813 .0255872 4.45 0.000 .0625348 .1654277
2005 | .1348639 .0266757 5.06 0.000 .0812288 .1884991
2006 | .1269117 .0277339 4.58 0.000 .0711488 .1826745
|
_cons | -.9676361 .0266693 -36.28 0.000 -1.021258 -.914014
-------------------+----------------------------------------------------------------
sigma_u | .03262543
sigma_e | .03651163
rho | .44396696 (fraction of variance due to u_i)
------------------------------------------------------------------------------------
. estimates store did_bbb
.
end of do-file
3、时间安慰剂检验
4、空间安慰剂检验
双尾检验P值较小,故可拒绝“处理效应为 0”的原假设
5、 混合安慰剂检验
. didplacebo did_bbb, treatvar(_intra) pbomix(2)
pbomix(2) 表示以无约束的方式 (version 2) 进行混合安慰剂检验
Implementing unrestricted mixed placebo test for staggered DID (version 2) using both fake t
> reatment units and times:
-------------------------------------------------------------------------
The number of units randomly | The range within which fake
selected as fake treatment units | treatment times are randomly selected
----------------------------------+--------------------------------------
49 | [1976, 2006]
-------------------------------------------------------------------------
Simulations (500):.........10.........20.........30.........40.........50.........60........
> .70.........80.........90.........100.........110.........120.........130.........140.....
> ....150.........160.........170.........180.........190.........200.........210.........22
> 0.........230.........240.........250.........260.........270.........280.........290.....
> ....300.........310.........320.........330.........340.........350.........360.........37
> 0.........380.........390.........400.........410.........420.........430.........440.....
> ....450.........460.........470.........480.........490.........500
Results of unrestricted mixed placebo test for staggered DID (version 2) using both fake tre
> atment units and times:
--------------------------------------------------------------
| | P-value
| Coefficient | Two-sided Left-sided right-sided
-----------+-------------+------------------------------------
_intra | -0.017724 | 0.0000 0.0000 1.0000
--------------------------------------------------------------
Note: (1) The two-sided p-value is the frequency that the absolute values of the placebo
effects are greater than or equal to the absolute value of estimated treatment
effect.
(2) The left-sided (right-sided) p-value is the frequency that the placebo effects
are smaller (greater) than or equal to the estimated treatment effect.
Finished.
.
end of do-file
.
双边 p 值和左边 p 值均为 0.000,故可强烈拒绝“处理效应为 0”
的原假设