跨期异质性处理效应did_multiplegt_dyn
#下载安装
ssc install did_multiplegt_dyn, replace
查看帮助文件
help did_multiplegt_dyn
Test the command
查看 did_multiplegt_dyn命令基本用法:
did_multiplegt_dyn Y id t D, effects(10) placebo(10) cluster(id)
将得到结果如下:
--------------------------------------------------------------------------------
Estimation of treatment effects: Event-study effects
--------------------------------------------------------------------------------
| Estimate SE LB CI UB CI N Switchers
-------------+-----------------------------------------------------------------
Effect_1 | -.0608394 .3275515 -.7028286 .5811498 78 23
Effect_2 | 8.49767 .3888474 7.735543 9.259797 78 23
Effect_3 | 17.64773 .3877416 16.88777 18.40769 78 23
Effect_4 | 25.9377 .3203208 25.30988 26.56551 78 23
Effect_5 | 34.62362 .3923778 33.85458 35.39267 75 23
Effect_6 | 42.85682 .3893014 42.09381 43.61984 64 19
Effect_7 | 51.93103 .3963844 51.15413 52.70793 64 19
Effect_8 | 60.13327 .3945513 59.35997 60.90658 64 19
Effect_9 | 68.82446 .4118019 68.01735 69.63158 64 19
Effect_10 | 77.30792 .4396869 76.44615 78.16969 64 19
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Average cumulative (total) effect per treatment unit
--------------------------------------------------------------------------------
| Estimate SE LB CI UB CI N Switch x Periods
-------------+----------------------------------------------------------------------------
Av_tot_eff | 36.72796 .2689364 36.20085 37.25506 641 210
--------------------------------------------------------------------------------
Average number of time periods over which a treatment's effect is accumulated = 5.2619048
--------------------------------------------------------------------------------
Testing the parallel trends and no anticipation assumptions
--------------------------------------------------------------------------------
| Estimate SE LB CI UB CI N Switchers
-------------+-----------------------------------------------------------------
Placebo_1 | .1308918 .4574125 -.7656203 1.027404 78 23
Placebo_2 | -.0635463 .3403349 -.7305904 .6034978 78 23
Placebo_3 | -.1275425 .3855322 -.8831717 .6280867 78 23
Placebo_4 | -.3848303 .3223237 -1.016573 .2469125 78 23
Placebo_5 | -.4583828 .3389718 -1.122755 .2059897 75 23
Placebo_6 | -.187576 .4510044 -1.071528 .6963763 64 19
Placebo_7 | .1194068 .4068627 -.6780295 .9168431 64 19
Placebo_8 | .0628537 .4251272 -.7703804 .8960877 64 19
Placebo_9 | -.1943702 .4963493 -1.167197 .7784565 64 19
Placebo_10 | -.2936846 .5040208 -1.281547 .694178 64 19
--------------------------------------------------------------------------------
Test of joint nullity of the placebos : p-value = .01289977
The development of this package was funded by the European Union (ERC, REALLYCREDIBLE,GA N°101043899).
如果未指定 graph_off 选项,则默认情况下,该命令始终返回事件研究图:
也可以使用event_plot
来生成事件研究图:
event_plot e(estimates)#e(variances), default_look ///
graph_opt(xtitle("Periods since the event") ytitle("Average causal effect") ///
title("did_multiplegt_dyn") xlabel(-10(1)10)) stub_lag(Effect_#) stub_lead(Placebo_#) together
结果为:
Stata:多期多个体倍分模型DIDm估计量——did_multiplegt
did_multiplegt使用具有多组和多期的组(如县或州)水平的面板数据,估计处理对结果的影响。截面可以是不平衡的,并不是所有的小组都必须在每个时期进行观察。意思可以是非平衡面板数据。
当处理效应存在异质性时,即使满足平行趋势假设,处理效应的估计结果也会存在偏误,因此可以根据de Chaisemartin 和 D’Haultfoeuille(2020、2022)提出的多期多个体倍分模型和对应的估计量(DIDM)进行估计。
下面我们介绍一下DIDm估计量,即 did_multiplegt命令
命令下载安装
ssc install did_multiplegt, replace
help did_multiplegt
findit did_multiplegt
语法格式:
did_multiplegt Y G T D [if] [in] [, robust_dynamic dynamic(#) placebo(#) firstdiff_placebo controls(varlist)
trends_nonparam(varlist) trends_lin(varlist) count_switchers_contr always_trends_nonparam always_trends_lin
recat_treatment(varlist) threshold_stable_treatment(#) weight(varlist) switchers(string) if_first_diff(string)
count_switchers_tot drop_larger_lower discount(#) breps(#) cluster(varname) seed(#) graphoptions(string)
save_results(path)]
主要选项含义:
Y是结果变量。
G是群变量。
T是时间周期变量。
该命令假设时间变量是均匀间隔的(例如:面板是在每年的水平上,并且所有组都没有遗漏年份)。如果不是这样(例如:面板是按年计算的,但所有组都缺少连续三年),则仍然可以使用该命令,尽管需要进行一些调整
D是处理变量。
robust_dynamic:如果未指定该选项,则计算de Chaisemartin和D'Haultfoeuille (2020a)中的估计量。如果指定,则计算de Chaisemartin和D'Haultfoeuille (2020b)中的估计量。
Dynamic(#)给出要估计的动态处理效果的个数。该选项只能在指定了robust_dynamic选项时使用。
placebo(#) 给出要估计的安慰剂估计的数量。
Controls (varlist)给出了要包含在评估中的所有控制变量的名称。
breps(#)给出了用于估计标准误差计算的自举次数。如果未指定该选项,则默认值为50。
cluster (varname)计算估计聚类到varname级别的标准误。
seed(#)设置种子值
存储的结果可以通过键入
ereturn list
来查看。
案例应用
首先,在这里我们生成一个具有多时点处理的测试数据集:
clear
local units = 30
local start = 1
local end = 60
local time = `end' - `start' + 1
local obsv = `units' * `time'
set obs `obsv'
egen id = seq(), b(`time')
egen t = seq(), f(`start') t(`end')
sort id t
xtset id t
set seed 20211222
gen Y = 0 // outcome variable
gen D = 0 // intervention variable
gen cohort = . // treatment cohort
gen effect = . // treatment effect size
gen first_treat = . // when the treatment happens for each cohort
gen rel_time = . // time - first_treat
levelsof id, local(lvls)
foreach x of local lvls {
local chrt = runiformint(0,5)
replace cohort = `chrt' if id==`x'
}
levelsof cohort , local(lvls)
foreach x of local lvls {
local eff = runiformint(2,10)
replace effect = `eff' if cohort==`x'
local timing = runiformint(`start',`end' + 20) //
replace first_treat = `timing' if cohort==`x'
replace first_treat = . if first_treat > `end'
replace D = 1 if cohort==`x' & t>= `timing'
}
replace rel_time = t - first_treat
replace Y = id + t + cond(D==1, effect * rel_time, 0) + rnormal()
生成图形:
让我们尝试基本命令:did_multiplegt
让我们尝试一个事件研究选项,其中包含 10 个处理前(在模型中称为安慰剂)和 10 个处理后:
did_multiplegt Y id t D, robust_dynamic dynamic(10) placebo(10) breps(20) cluster(id)
我们得到这个结果:
尽管在上面的输出中警告我们不应该比较事件研究估计值,但我们仍然可以使用 event_plot后面() 命令绘制这些估计值,如下所示:
event_plot命令可以如下安装
ssc install event_plot, replace
event_plot e(estimates)#e(variances), default_look ///
graph_opt(xtitle("Periods since the event") ytitle("Average causal effect") ///
title("did_multiplegt") xlabel(-10(1)10)) stub_lag(Effect_#) stub_lead(Placebo_#) together
我们得到这个图:
案例2
下面我们使用面板数据wagepan来估计参加工会对于工资的影响。使用 did_multiplegt
命令估计状态转换 (switchers) 的平均处理效应。
ssc install bcuse
bcuse wagepan
did_multiplegt lwage nr year union, placebo(1) breps(100) cluster(nr)
did_multiplegt lwage nr year union, robust_dynamic dynamic(1) placebo(1) breps(100) cluster(nr)
结果为:
. did_multiplegt lwage nr year union, placebo(1) breps(100) cluster(nr)
DID estimators of the instantaneous treatment effect, of dynamic treatment effects if the dynamic option is used, and of
placebo tests of the parallel trends assumption if the placebo option is used. The estimators are robust to
heterogeneous effects, and to dynamic effects if the robust_dynamic option is used.
| Estimate SE LB CI UB CI N Switchers
-------------+------------------------------------------------------------------
Effect_0 | .0261226 .0225804 -.0181349 .0703801 3815 508
Placebo_1 | .0993211 .0273153 .0457831 .1528591 2842 247
.
结果表明加入工会可以提高工资2.61%。