推荐3篇《数量经济技术经济研究》2024年第3期上使用ddtiming命令进行培根分解的论文
论文1:全国统一大市场与经济增长——来自安徽省加入长三角城市经济协调会的证据
构建渐进双重差分模型,采用Goodman-Bacon分解进行稳健性检验
使用的命令为ddtiming,复刻结果为:
上述结果与附表4结果完全一致。根据附录表4的数据显示,恰当的处理效应估计数为1.845,其对应的权重高达77.1%,占据了较大的比例;而不恰当的处理效应估计数为0.642,其权重为22.9%,占比相对较小。这些发现支持了基准回归估计值并未受到显著偏差影响的观点。
论文2:“亩均论英雄”改革与企业高质量发展——基于效率变革和动力变革的视角
渐进式双重差分模型
平行趋势检验
诚实双重差分方法(Honest DID)
双向固定效应偏误识别与异质性处理效应检验
安慰剂检验
稳健性检验
采用Goodman-Bacon分解进行稳健性检验 ,使用的命令为ddtiming,复刻结果为:
原文结果为:
论文3:推荐文章:碳达峰目标如何引领城市低碳转型——来自准自然实验的证据
psm
psmatch2
pstest
描述性统计
tabstat
基准回归
xtreg
平行趋势
xtreg
coefplot
异质性处理偏误
ddtiming
twowayfeweights
Bacon分解
Goodman-Bacon(2021)指出多时点DID分析中,采用双向固定效应估计量等于所有可能的2*2 DID双重差分估计量的加权平均值,可能存在偏误。
根据 Goodman-Bacon (2021)的研究,所有的2x2-DID估计值可以分为三类,即“新处理个体”(实验组)将“未处理个体”当作对照组、"新处理个体”(实验组)将“尚未”处理的个体当作对照组以及“新处理个体”(实验组)将“已经处理”过的个体当作对照组。第三类结果变量中已经包含了处理效应,所寻找的对照组并不是科学的。
采用Goodman-Bacon分解法进行检验。结果如下:
培根分解结果表明:
组1以“尚未接受处理组”为控制组
组2是以“较早接受处理组”作为对照的“不良”控制组,权重仅为1.3%
组3是以“从未接受处理组”作为对照的“良好”控制组,权重达到95.3%,几乎解释了全部基线回归结果。
这意味着估计结果受异质性处理效果的影响较小,本研究结果仍然稳健
原文使用ddtiming命令代码为:
ddtiming lncg tg,i(dist) t(year)
Calculating treatment times...
Calculating weights...
Estimating 2x2 diff-in-diff regressions...
estimate: -0.266
DD Comparison Weight Avg DD Est
-------------------------------------------------
Earlier T vs. Later C 0.034 0.093
Later T vs. Earlier C 0.013 -0.258
T vs. Never treated 0.953 -0.279
-------------------------------------------------
T = Treatment; C = Comparison
ddtiming lnco2 tg,i(dist) t(year)
Calculating treatment times...
Calculating weights...
Estimating 2x2 diff-in-diff regressions...
estimate: -0.213
DD Comparison Weight Avg DD Est
-------------------------------------------------
Earlier T vs. Later C 0.034 0.064
Later T vs. Earlier C 0.013 -0.320
T vs. Never treated 0.953 -0.222
-------------------------------------------------
T = Treatment; C = Comparison
end of do-file
ddtiming命令简介
ddtiming是一个Stata命令,基于Goodman-Bacon(2021), 实现了双重差分(DD)估计随处理时间变化的分解。双向固定效应DD模型是所有可能的两组/两期DD估计量的加权平均。该命令生成 2x2 DD估计值及其相关权重的散点图。
R用户可以使用名为bacondecomp的R包执行分解。
注意事项:Stata用户应该使用bacondecomp,这是Stata中Bacon分解的最新实现。
安装
要在 Stata 中安装命令,请在命令窗口中键入ddtiming
net describe ddtiming, from(https://tgoldring.com/code)
net install ddtiming
或输入
net install ddtiming, from(https://tgoldring.com/code)
示例 – 无过错离婚法
ddtiming
可以复制古德曼-培根 (2021) 中的例子。下载并加载一个数据集,其中包含无过错离婚法和女性自杀率数据(Stevenson & Wolfers,2006):
net get ddtiming
use nofault_divorce.dta
为了进行比较,估计女性自杀对无过错离婚改革的双向固定效应DD模型:
areg asmrs treat i.year, a(state) vce(robust)
将Goodman-Bacon(2018)中的DD分解定理应用于双向固定效应DD模型:
ddtiming asmrs treat, i(state) t(year)
Stata 将生成 DD 估计值、相关权重和估计值的散点图。散点图复制了Goodman-Bacon (2021) 中的图 (6)。此外,我们可以在命令中添加选项来修改散点图的外观:
ddtiming asmrs treat, i(state) t(year) ddline(lwidth(thick)) ///
ylabel(-30(10)30) legend(order(3 4 1 2)) savegraph(nfd.jpg) ///
savedata(nfd) replace
操作结果
引文
请引用为:ddtiming
Goldring, T. (2019). ddtiming: Stata module to perform a Goodman-Bacon decomposition of difference-in-differences estimation. tgoldring.github.io/projects/ddtiming
References
Goodman-Bacon, A. (2021). Difference-in-differences with variation in treatment timing. Journal of Econometrics, 225(2), 254–277.
Stevenson, B., & Wolfers, J. (2006). Bargaining in the Shadow of the Law: Divorce Laws and Family Distress. The Quarterly Journal of Economics, 121(1): 267–288.
本视频里面用到的数据以及案例代码
要在Stata中安装ddtiming命令,可以在命令窗口中键入任意一种命令
net describe ddtiming, from(https://tgoldring.com/code)
net install ddtiming
*or type
net install ddtiming, from(https://tgoldring.com/code)
*- 例子-单边离婚法
* ddtiming可以复制Goodman-Bacon(2021)中的例子。
* 下载并加载无过错离婚法和女性自杀率的时间数据集(Stevenson & Wolfers, 2006):
net get ddtiming
use nofault_divorce.dta
*注意,我们还是使用的为3月23日视频里面介绍那个案例数据
use bacon_example.dta, clear
areg asmrs post i.year, a( stfips ) vce(robust)
结果省略
ddtiming asmrs post, i( stfips) t(year)
Calculating treatment times...
Calculating weights...
Estimating 2x2 diff-in-diff regressions...
Diff-in-diff estimate: -3.080
DD Comparison Weight Avg DD Est
-------------------------------------------------
Earlier T vs. Later C 0.111 -0.187
Later T vs. Earlier C 0.265 3.512
T vs. Never treated 0.240 -5.331
T vs. Already treated 0.384 -7.044
-------------------------------------------------
T = Treatment; C = Comparison
ssc install bacondecomp
checking bacondecomp consistency and verifying not already installed...
installing into c:\ado\plus\...
installation complete.
. adoedit bacondecomp
c:\ado\plus/b/bacondecomp.ado
. bacondecomp asmrs post , ddetail
Computing decomposition across 14 timing groups
including an always-treated group and a never-treated group
------------------------------------------------------------------------------
asmrs | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
post | -3.079926 1.111656 -2.77 0.006 -5.258732 -.9011193
------------------------------------------------------------------------------
Bacon Decomposition
+---------------------------------------------------+
| | Beta TotalWeight |
|----------------------+----------------------------|
| Early_v_Late | 3.089867353 .0001259938 |
| Late_v_Early | -23.83420181 .0006803664 |
| Early_v_Late | .7286439538 .0008819564 |
| Late_v_Early | -8.258329391 .0045861736 |
| Early_v_Late | 2.404874802 .0005291738 |
| Late_v_Early | 22.15005112 .0022930868 |
| Early_v_Late | 1.676301956 .000566972 |
| Late_v_Early | -7.148348331 .00283486 |
| Early_v_Late | 4.613049507 .0004535776 |
| Late_v_Early | 26.58180046 .0018899067 |
| Early_v_Late | -7.006736755 .0009260543 |
| Late_v_Early | -5.394356728 .0033073366 |
| Early_v_Late | .6727053523 .0025198756 |
| Late_v_Early | -7.43382597 .012095402 |
| Early_v_Late | 3.899661064 .0022678879 |
| Late_v_Early | 27.04117584 .0090715515 |
| Early_v_Late | -7.521428585 .0061736949 |
| Late_v_Early | -6.398066521 .0211669536 |
| Early_v_Late | -3.244979858 .0015119253 |
| Late_v_Early | -3.630996227 .0045357758 |
| Early_v_Late | .1488796175 .0009449533 |
| Late_v_Early | -5.158778191 .0043467852 |
| Early_v_Late | -2.910137653 .0009071552 |
| Late_v_Early | 23.89071274 .0034774283 |
| Early_v_Late | -9.381551743 .0027781627 |
| Late_v_Early | -6.318483829 .009128249 |
| Early_v_Late | -8.437994003 .0009071552 |
| Late_v_Early | -6.468858719 .0026080712 |
| Early_v_Late | 4.291956902 .001700916 |
| Late_v_Early | 6.192469597 .0043467852 |
| Early_v_Late | 9.615415573 .0007559626 |
| Late_v_Early | .6682447195 .0033262358 |
| Early_v_Late | 5.732773304 .0007559626 |
| Late_v_Early | 29.61791611 .002771863 |
| Early_v_Late | 2.411342144 .002469478 |
| Late_v_Early | 4.052882671 .0077612166 |
| Early_v_Late | 5.130411148 .0009071552 |
| Late_v_Early | 4.886719704 .0024946767 |
| Early_v_Late | 8.392121315 .0022678879 |
| Late_v_Early | 10.78344917 .0055437261 |
| Early_v_Late | 3.15568161 .0003779813 |
| Late_v_Early | 3.873969555 .0008315589 |
| Early_v_Late | 3.482367754 .0004409782 |
| Late_v_Early | 4.239864349 .0018521086 |
| Early_v_Late | -7.72107935 .0004535776 |
| Late_v_Early | 28.58859062 .0015875215 |
| Early_v_Late | -8.404179573 .0015434237 |
| Late_v_Early | 3.740804911 .0046302713 |
| Early_v_Late | -9.093745232 .0006047701 |
| Late_v_Early | .6837824583 .0015875215 |
| Early_v_Late | 1.421976328 .001700916 |
| Late_v_Early | 11.66159821 .0039688039 |
| Early_v_Late | -16.38343239 .0003779813 |
| Late_v_Early | -6.338175297 .0007937608 |
| Early_v_Late | -14.61515999 .0001385932 |
| Late_v_Early | -7.964285851 .0002645869 |
| Early_v_Late | -3.567538977 .0015119253 |
| Late_v_Early | -13.05292702 .006047701 |
| Early_v_Late | -10.86773682 .0015875215 |
| Late_v_Early | 13.24829674 .0052917384 |
| Early_v_Late | -7.6874547 .0055563254 |
| Late_v_Early | -9.137350082 .0158752156 |
| Early_v_Late | -6.326669693 .0022678879 |
| Late_v_Early | -11.05425262 .0056697199 |
| Early_v_Late | 4.825609684 .0068036641 |
| Late_v_Early | .64386338 .0151192535 |
| Early_v_Late | 2.691236258 .001700916 |
| Late_v_Early | -4.655465126 .0034018321 |
| Early_v_Late | 1.836740971 .0008315589 |
| Late_v_Early | -6.611749649 .0015119253 |
| Early_v_Late | 20.30932999 .0002267888 |
| Late_v_Early | 7.368327141 .0003779813 |
| Early_v_Late | 3.358542204 .0006929658 |
| Late_v_Early | -4.764940262 .0023560837 |
| Early_v_Late | -9.930462837 .0007559626 |
| Late_v_Early | 19.64731598 .0021418943 |
| Early_v_Late | -2.845511436 .0027781627 |
| Late_v_Early | -.215427205 .0067469666 |
| Early_v_Late | -3.231632233 .0012095402 |
| Late_v_Early | -2.357027531 .0025702729 |
| Early_v_Late | 3.202227831 .0039688039 |
| Late_v_Early | 6.197752476 .0074966296 |
| Early_v_Late | -.0546139181 .0011339439 |
| Late_v_Early | .2491527498 .0019277048 |
| Early_v_Late | -4.581885338 .0006929658 |
| Late_v_Early | -6.757017612 .0010709471 |
| Early_v_Late | 23.70957756 .0003023851 |
| Late_v_Early | 21.65239143 .0004283788 |
| Early_v_Late | -5.129266739 .0007370636 |
| Late_v_Early | 2.485960007 .0009638524 |
| Early_v_Late | 9.392490387 .0009449533 |
| Late_v_Early | .7609612942 .0024568787 |
| Early_v_Late | -8.653765678 .0010583477 |
| Late_v_Early | 20.62852859 .0022930868 |
| Early_v_Late | 2.299735785 .0040129018 |
| Late_v_Early | 3.604630232 .0074525319 |
| Early_v_Late | 3.223866224 .0018143104 |
| Late_v_Early | 4.552188396 .0029482542 |
| Early_v_Late | 6.547305107 .006236692 |
| Late_v_Early | 10.9064064 .0090085548 |
| Early_v_Late | 5.205688 .0018899067 |
| Late_v_Early | 6.71902132 .0024568787 |
| Early_v_Late | -.8521057963 .0012473383 |
| Late_v_Early | -2.820950985 .0014741271 |
| Early_v_Late | 17.60421181 .0006047701 |
| Late_v_Early | 19.93760681 .0006551676 |
| Early_v_Late | -2.688749552 .001719815 |
| Late_v_Early | 9.5492239 .001719815 |
| Early_v_Late | -1.343767166 .0004031801 |
| Late_v_Early | 1.879976273 .0003275838 |
| Early_v_Late | -1.982551336 .0010079502 |
| Late_v_Early | 8.675222397 .0024190804 |
| Early_v_Late | -19.76277542 .0011339439 |
| Late_v_Early | 28.40373802 .0022678879 |
| Early_v_Late | -5.887892723 .0043215866 |
| Late_v_Early | 11.7344656 .0074084342 |
| Early_v_Late | -.348316431 .001965503 |
| Late_v_Early | 13.98102951 .0029482542 |
| Early_v_Late | 6.036512852 .0068036641 |
| Late_v_Early | 21.13029671 .0090715515 |
| Early_v_Late | 3.112169027 .0020788973 |
| Late_v_Early | 16.37677193 .0024946767 |
| Early_v_Late | .1411235332 .0013859315 |
| Late_v_Early | 9.925600052 .0015119253 |
| Early_v_Late | 16.27362823 .0006803664 |
| Late_v_Early | 29.59807777 .0006803664 |
| Early_v_Late | -1.641644478 .001965503 |
| Late_v_Early | 22.16219139 .0018143104 |
| Early_v_Late | -2.667479753 .0005039751 |
| Late_v_Early | 12.13856983 .0003779813 |
| Early_v_Late | 5.63313818 .0001259938 |
| Late_v_Early | 16.86439133 .0000755963 |
| Always_v_timing | -7.043688925 .3844322134 |
| Never_v_timing | -5.330906825 .2402701287 |
+---------------------------------------------------+