多時(shí)點(diǎn)did安慰劑檢驗(yàn)代碼
************************多時(shí)點(diǎn)did安慰劑檢驗(yàn)*******
clear
set matsize 5000
mat b = J(500,1,0)
mat se = J(500,1,0)
mat p = J(500,1,0)
forvalues i=1/500{
use "did.dta" , clear?
xtset stkcd year?
keep if year==2004
sample 93, count
keep city
save "atchcity.dta",replace
merge 1:m city using "did.dta"
gen groupnew=(_merge==3) //生成偽處理組的虛擬變量
save "matchcity`i'.dta",replace
*偽政策虛擬變量
use "數(shù)據(jù).dta",clear?
bsample 1, strata(city)
keep year
save "matchyear.dta", replace
mkmat year, matrix(sampleyear)
use "matchcity`i'.dta",replace
xtset city year
gen time = 0
foreach j of numlist 1/280 {
replace time = 1 if (city == `j' & year >= sampleyear[`j',1])
}
gen? did=time*groupnew
global xlist? "lnagdp indust_stru finance ainternet market "
xtreg entre_activation did? $xlist? i.year, fe robust
mat b[`i',1] = _b[did]
mat se[`i',1] = _se[did]
scalar df_r = e(N) - e(df_m) -1
mat p[`i',1] = 2*ttail(df_r,abs(_b[did]/_se[did]))
}
svmat b, names(coef)
svmat se, names(se)
svmat p, names(pvalue)
drop if pvalue1 == .
label var pvalue1 p值
label var coef1 估計(jì)系數(shù)
?twoway (scatter pvalue1 coef1,? xlabel(-0.2(0.05)0.4, grid) yline(0.1,lp(shortdash)) xline(0.2997,lp(shortdash)) xtitle(估計(jì)系數(shù)) ytitle(p值) msymbol(smcircle_hollow) mcolor(grey) legend(off)) (kdensity coef1, title(安慰劑檢驗(yàn)))
?*-刪除臨時(shí)文件
forvalue i=1/500{
? ? erase? "matchcity`i'.dta"
}