午夜视频在线网站,日韩视频精品在线,中文字幕精品一区二区三区在线,在线播放精品,1024你懂我懂的旧版人,欧美日韩一级黄色片,一区二区三区在线观看视频

分享

一張圖里畫出5種異質性穩(wěn)健DID的平行趨勢與動態(tài)效應的完整code和示例

 計量經(jīng)濟圈 2024-06-08 發(fā)布于浙江

接著1.最新: 2024版異質性穩(wěn)健DID最全指南! 更新太快腦袋跟不上看這里!2.不炒冷飯! 2024年最新“2”份DID使用檢查清單, 前沿DID使用基本規(guī)范指南! 今天展示一個在一張圖里畫出5種異質性穩(wěn)健DID方法的平行趨勢與動態(tài)效應的完整code和示例。

該示例將指導你如何在單張圖表中繪制五種不同估計方法下的異質性穩(wěn)健雙重差分估計值(DID)。不僅展示了事前平行趨勢,還揭示了動態(tài)效應的演變過程??梢灾庇^地觀察不同處理組在政策或事件影響前后的變化趨勢,從而更準確地評估政策或事件的因果效應。

關于平行趨勢,1.平行趨勢檢驗, 事件研究圖繪制, 安慰劑檢驗的保姆級程序指南!2.標準DID中的平行趨勢檢驗,動態(tài)效應, 安慰劑檢驗, 預期效應教程,3.平行趨勢通不過, 該采取什么方法來更好地滿足平行趨勢呢?4.平行趨勢的敏感性檢驗, 結果能容忍違反多大程度的平行趨勢,5.某經(jīng)濟學權威刊物上平行趨勢怎么這樣, 真給我看迷糊了! 到底如何對pre-trend檢測, 討論和處理呢?6.在平行趨勢檢驗中對政策前后系列年份進行縮尾處理?7.三重差分DDD估計中平行趨勢檢驗如何操作呢?8.2篇TOP5: 當前平行趨勢檢驗方法有問題,新的平行趨勢檢驗方法已經(jīng)出現(xiàn),9.前沿: 平行趨勢沒有通過卻成功發(fā)在了AER上!10.只有4期數(shù)據(jù), 為啥平行趨勢檢驗時有6期呢? DID與連續(xù)變量交互系數(shù)如何解釋? 11.歷史上首篇DID中修改平行趨勢而被撤稿的TOP5文章!
直接通過一個程序在一張圖里畫出5種異質性穩(wěn)健DID的平行趨勢和政策動態(tài)效應。
模擬示例分析:事件研究中的因果效應估計方法
本文通過一系列方法的模擬示例,向讀者展示了如何估計事件研究中的因果效應。同時,介紹了如何利用event_plot命令繪制系數(shù)及其置信區(qū)間,以直觀展示研究結果。
作者:Kirill Borusyak
在進行執(zhí)行代碼之前,需要準備以下統(tǒng)計命令:
did_imputation(Borusyak等,2021):可通過SSC平臺獲取。
did_multiplegt(de Chaisemartin和D'Haultfoeuille,2020):同樣可在SSC平臺下載。
eventstudyinteract(San和Abraham,2020):SSC上也有提供。
csdid(Callaway和Sant'Anna,2020):SSC平臺亦可下載。

下面的代碼是上圖完整的示例code,里面包括了自己模擬的數(shù)據(jù),因此可以完整運行下來。

*群友可直接前往社群下載。
// 生成模擬數(shù)據(jù),Generate a complete panel of 300 units observed in 15 periods
clear all
timer clear
set seed 10
global T = 15
global I = 300

set obs `=$I*$T'
gen i = int((_n-1)/$T )+1 // unit id
gen t = mod((_n-1),$T )+1 // calendar period
tsset i t

// Randomly generate treatment rollout years uniformly across Ei=10..16 (note that periods t>=16 would not be useful since all units are treated by then)
gen Ei = ceil(runiform()*7)+$T -6 if t==1 // year when unit is first treated
bys i (t): replace Ei = Ei[1]
gen K = t-Ei // "relative time", i.e. the number periods since treated (could be missing if never-treated)
gen D = K>=0 & Ei!=. // treatment indicator

// Generate the outcome with parallel trends and heterogeneous treatment effects
gen tau = cond(D==1, (t-12.5), 0) // heterogeneous treatment effects (in this case vary over calendar periods)
gen eps = rnormal() // error term
gen Y = i + 3*t + tau*D + eps // the outcome (FEs play no role since all methods control for them)
//save five_estimators_data, replace

//  did_imputation估計,Estimation with did_imputation of Borusyak et al. (2021)
did_imputation Y i t Ei, allhorizons pretrend(5)
event_plot, default_look graph_opt(xtitle("Periods since the event") ytitle("Average causal effect") ///
title("Borusyak et al. (2021) imputation estimator") xlabel(-5(1)5))

estimates store bjs // storing the estimates for later

// Estimation with did_multiplegt of de Chaisemartin and D'Haultfoeuille (2020)
did_multiplegt Y i t D, robust_dynamic dynamic(5) placebo(5) breps(100) cluster(i) 
event_plot e(estimates)#e(variances), default_look graph_opt(xtitle("Periods since the event") ytitle("Average causal effect") ///
title("de Chaisemartin and D'Haultfoeuille (2020)") xlabel(-5(1)5)) stub_lag(Effect_#) stub_lead(Placebo_#) together

matrix dcdh_b = e(estimates) // storing the estimates for later
matrix dcdh_v = e(variances)

// csdid估計, Estimation with csdid of Callaway and Sant'Anna (2020)
gen gvar = cond(Ei==., 0, Ei) // group variable as required for the csdid command
csdid Y, ivar(i) time(t) gvar(gvar) notyet
estat event, estore(cs) // this produces and stores the estimates at the same time
event_plot cs, default_look graph_opt(xtitle("Periods since the event") ytitle("Average causal effect") xlabel(-14(1)5) ///
title("Callaway and Sant'Anna (2020)")) stub_lag(Tp#) stub_lead(Tm#) together

//  eventstudyinteract估計,Estimation with eventstudyinteract of Sun and Abraham (2020)
sum Ei
gen lastcohort = Ei==r(max) // dummy for the latest- or never-treated cohort
forvalues l = 0/5 {
gen L`l'event = K==`l'
}
forvalues l = 1/14 {
gen F`l'event = K==-`l'
}
drop F1event // normalize K=-1 (and also K=-15) to zero
eventstudyinteract Y L*event F*event, vce(cluster i) absorb(i t) cohort(Ei) control_cohort(lastcohort)
event_plot e(b_iw)#e(V_iw), default_look graph_opt(xtitle("Periods since the event") ytitle("Average causal effect") xlabel(-14(1)5) ///
title("Sun and Abraham (2020)")) stub_lag(L#event) stub_lead(F#event) together

matrix sa_b = e(b_iw) // storing the estimates for later
matrix sa_v = e(V_iw)

//  TWFE估計,TWFE OLS estimation (which is correct here because of treatment effect homogeneity). Some groups could be binned.
reghdfe Y F*event L*event, a(i t) cluster(i)
event_plot, default_look stub_lag(L#event) stub_lead(F#event) together graph_opt(xtitle("Days since the event") ytitle("OLS coefficients") xlabel(-14(1)5) ///
title("OLS"))

estimates store ols // saving the estimates for later

// Construct the vector of true average treatment effects by the number of periods since treatment
matrix btrue = J(1,6,.)
matrix colnames btrue = tau0 tau1 tau2 tau3 tau4 tau5
qui forvalues h = 0/5 {
sum tau if K==`h'
matrix btrue[1,`h'+1]=r(mean)
}
// 一張圖里展示所有估計值的事前趨勢與事后動態(tài)效應,Combine all plots using the stored estimates
// Combine all plots using the stored estimates
event_plot btrue# bjs dcdh_b#dcdh_v cs sa_b#sa_v ols, ///
stub_lag(tau# tau# Effect_# Tp# L#event L#event) stub_lead(pre# pre# Placebo_# Tm# F#event F#event) plottype(scatter) ciplottype(rcap) ///
together perturb(-0.325(0.13)0.325) trimlead(5) noautolegend ///
graph_opt(title("Event study estimators in a simulated panel (300 units, 15 periods)", size(medlarge)) ///
xtitle("Periods since the event") ytitle("Average causal effect") xlabel(-5(1)5) ylabel(0(1)3) ///
legend(order(1 "True value" 2 "Borusyak et al." 4 "de Chaisemartin-D'Haultfoeuille" ///
6 "Callaway-Sant'Anna" 8 "Sun-Abraham" 10 "OLS") rows(3) region(style(none))) ///
/// the following lines replace default_look with something more elaborate
xline(-0.5, lcolor(gs8) lpattern(dash)) yline(0, lcolor(gs8)) graphregion(color(white)) bgcolor(white) ylabel(, angle(horizontal)) ///
) ///
lag_opt1(msymbol(+) color(cranberry)) lag_ci_opt1(color(cranberry)) ///
lag_opt2(msymbol(O) color(cranberry)) lag_ci_opt2(color(cranberry)) ///
lag_opt3(msymbol(Dh) color(navy)) lag_ci_opt3(color(navy)) ///
lag_opt4(msymbol(Th) color(forest_green)) lag_ci_opt4(color(forest_green)) ///
lag_opt5(msymbol(Sh) color(dkorange)) lag_ci_opt5(color(dkorange)) ///
lag_opt6(msymbol(Oh) color(purple)) lag_ci_opt6(color(purple)) 
graph export "five_estimators_example.png", replace
關于多期DID或交疊DID: 1.DID相關前沿問題“政策交錯執(zhí)行+堆疊DID+事件研究”, 附完整slides,2.交錯(漸進)DID中, 用TWFE估計處理效應的問題, 及Bacon分解識別估計偏誤,3.典范! 這篇AER在一圖表里用了所有DID最新進展方法, 審稿人直接服了!4.最新Sun和Abraham(2020)和TWFE估計多期或交錯DID并繪圖展示結果!詳細解讀code!5.多期DID或漸進DID或交疊DID, 最新Stata執(zhí)行命令整理如下供大家學習,6.多期DID前沿方法大討論, e.g., 進入-退出型DID, 異質性和動態(tài)性處理效應DID, 基期選擇問題等,7.交疊DID中平行趨勢檢驗, 事件研究圖繪制, 安慰劑檢驗的保姆級程序指南!8.欣慰! 營養(yǎng)午餐計劃終于登上TOP5! 交疊DID+異質性穩(wěn)健DID!9.用事件研究法開展政策評估的過程, 手把手教學文章!10.從雙重差分法到事件研究法, 雙重差分濫用與需要注意的問題,11.系統(tǒng)梳理DID最新進展: 從多期DID的潛在問題到當前主流解決方法和代碼! 12.標準DID中的平行趨勢檢驗,動態(tài)效應, 安慰劑檢驗, 預期效應教程,13.DID從經(jīng)典到前沿方法的保姆級教程, 釋放最完整數(shù)據(jù)和代碼!
下面這些短鏈接文章屬于合集,可以收藏起來閱讀,不然以后都找不到了。

7年,計量經(jīng)濟圈近2000篇不重類計量文章,

可直接在公眾號菜單欄搜索任何計量相關問題,

Econometrics Circle




數(shù)據(jù)系列空間矩陣 | 工企數(shù)據(jù) | PM2.5 | 市場化指數(shù) | CO2數(shù)據(jù) |  夜間燈光 官員方言  | 微觀數(shù)據(jù) | 內(nèi)部數(shù)據(jù)
計量系列匹配方法 | 內(nèi)生性 | 工具變量 | DID | 面板數(shù)據(jù) | 常用TOOL | 中介調(diào)節(jié) | 時間序列 | RDD斷點 | 合成控制 | 200篇合輯 | 因果識別 | 社會網(wǎng)絡 | 空間DID
數(shù)據(jù)處理Stata | R | Python | 缺失值 | CHIP/ CHNS/CHARLS/CFPS/CGSS等 |
干貨系列能源環(huán)境 | 效率研究 | 空間計量 | 國際經(jīng)貿(mào) | 計量軟件 | 商科研究 | 機器學習 | SSCI | CSSCI | SSCI查詢 | 名家經(jīng)驗

    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多