楼主: 张哈哈_
399 2

[面板数据求助] 多期DID平行趋势检验结果求助 [推广有奖]

  • 0关注
  • 0粉丝

学前班

40%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
20 点
帖子
1
精华
0
在线时间
0 小时
注册时间
2024-2-23
最后登录
2024-2-23

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
请问使用stata跑完之后 出现的是这个结果 可能是哪一个步骤出现了问题呢?
另外 代码中并没有要求绘出Time等,却在图片中出现了。
球球各位大佬啦
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:DID Stata time tata IME

微信图片_20240223181032.png (100.7 KB)

微信图片_20240223181032.png

沙发
陈小丽 发表于 2024-2-23 20:39:43 |只看作者 |坛友微信交流群
stata一套多期did的代码,免费答疑群stata毕设答疑4群681893191
use data,clear
replace Time=. if Time==3333
rename Time pt
g Post=0
replace Post=1 if pt==2016&year>=2016
replace Post=1 if pt==2017&year>=2017
replace Post=1 if pt==2018&year>=2018
replace Post=1 if pt==2019&year>=2019
replace Post=1 if pt==2020&year>=2020
replace Post=1 if pt==2021&year>=2021
replace Post=1 if pt==2022&year>=2022
gen DID=Treat*Post

*cap drop missingv
*gen missingv=missing(TobinQ1,DID,TobinQ2,Size,Liquid,Lev,ATO,ROA,ListAge,Dual,TOP1)
*keep if missingv==0
global y "TobinQ1"
global y1 "TobinQ2"
global x "DID"
global m "ESG"
global control " Size Liquid Lev ATO ROA ListAge Dual Top1"
set matsize 5000
*描述性统计
outreg2 using msxtj.doc, replace sum(log) keep($y $x $control)
*相关性分析
logout, save(相关性分析) word replace: pwcorr_a ($y $x $control)
*多重共线性
reg $y $x $control
estat vif
logout,save(多重共线性检验) word replace: estat vif
*基准回归
eststo clear
eststo:reghdfe $y $x $control ,absorb(id year) vce(cluster id)
eststo:reghdfe $y1 $x $control ,absorb(id year) vce(cluster id)  
esttab using 基准回归.rtf, replace b(3) r2 ar2 star(* 0.1 ** 0.05 *** 0.01) nogap title(基准回归分析)

*平行趋势检验
gen distance=year-pt
replace distance = -4 if distance <= -4
tab distance,missing
forvalues i=1/4{
     gen d_`i'  = 0
     replace d_`i'  = 1 if Treat== 1 & distance== -`i'
}

forvalues i=1/6 {
     gen d`i'  = 0
     replace d`i'  = 1 if Treat== 1 & distance== `i'
}
gen d0  = 0
replace d0 = 1 if Treat== 1 & distance== 0
reghdfe $y $control  d_3 d_2 d_1 d0 d1 d2 d3 d4 d5 d6 ,absorb(id year) vce(cluster id)
graph set window fontface "Times New Roman"
graph set window fontfacesans "宋体"
coefplot, keep( d_3 d_2 d_1 d0 d1 d2 d3 d4 d5 d6) coeflabels(  d_3="-3" d_2="-2" d_1="-1" d0="0" d1="1"     d2="2"  d3="3"  d4="4"  d5="5" d6="6" d7="7" d8="8" )     yline(0,lcolor(edkblue*0.8))     ylabel(0(0.5)1.5,labsize(medsmall) format(%02.1f))        vertical addplot(line @b @at) ytitle("{stSans:系}"        "{stSans:数}", size(medsmall) orientation(h))             xtitle("{stSans:绿色债券的平行趋势检验}",      size(medsmall)) yline(0) levels(90) scheme(s2color)       ciopts(recast(rcap) lpattern(dash)) graphregion(fcolor(none))


*安慰剂检验
use data,clear
cap erase "simulations.dta"
permute DID beta=_b[DID] se=_se[DID] df=e(df_r),reps(500) seed(123) saving("simulations.dta"):reghdfe $y $x $control ,absorb(id year) vce(cluster id)
use "simulations.dta",clear
gen t_value=beta/se
gen p_value=2*ttail(df,abs(beta/se))
dpplot beta,xtitle("Estimator",size(*0.8)) xlabel(,format(%4.3f) labsize(small)) ytitle("Density",size(*0.8)) ylabel(,nogrid format(%4.3f) labsize(small)) note("") caption("") graphregion(fcolor(white))


*安慰剂检验
mat b = J(1000,1,0)
mat se = J(1000,1,0)
mat p = J(1000,1,0)
forvalues i=1/1000{
    use data.dta, clear
    qui xtset id year  
        keep if DID==1
    sample 1, count by(id)
    keep id year
    rename year policy_year
    save match_id_year.dta, replace
    merge 1:m id using data.dta
    qui xtset id year
    gen treatment = (_merge == 3)      
    gen period = (year >= policy_year)
    gen did = treatment*period
    *append using cao_control.dta
        reghdfe $y did $control,absorb(id year) vce(cluster id)
    mat b[`i',1] = _b[did]   
    mat se[`i',1] = _se[did]
    mat p[`i',1] = 2*ttail(e(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 估计系数
keep coef1 se1 pvalue1  
gen tvalue = coef1/se1     
save placebo.dta, replace  
kdensity coef1, normal scheme(qleanmono)

use data,clear
g Post_1=0
replace Post_1=1 if pt==2016&year>=2015
replace Post_1=1 if pt==2017&year>=2016
replace Post_1=1 if pt==2018&year>=2017
replace Post_1=1 if pt==2019&year>=2018
replace Post_1=1 if pt==2020&year>=2019
replace Post_1=1 if pt==2021&year>=2020
replace Post_1=1 if pt==2022&year>=2021
gen DID_1=Treat*Post_1
g Post1=0
replace Post1=1 if pt==2016&year>=2017
replace Post1=1 if pt==2017&year>=2018
replace Post1=1 if pt==2018&year>=2019
replace Post1=1 if pt==2019&year>=2020
replace Post1=1 if pt==2020&year>=2021
replace Post1=1 if pt==2021&year>=2022
replace Post1=1 if pt==2022&year>=2023
gen DID1=Treat*Post1


eststo clear
psmatch2 $x $control,outcome($y) n(1)
eststo :reghdfe $y DID_1 $control ,absorb(id year) vce(cluster id)
eststo :reghdfe $y DID1 $control,absorb(id year) vce(cluster id)
esttab  using 稳健性检验.rtf, replace b(3) r2 ar2 star(* 0.1 ** 0.05 *** 0.01) nogap
*中介
eststo clear
eststo:reghdfe $y $x $control  ,absorb(id year) vce(cluster id)
eststo:reghdfe $m $x $control  ,absorb(id year) vce(cluster id)
eststo:reghdfe $y $x $m $control ,absorb(id year) vce(cluster id)  
esttab  using 中介.rtf, replace b(3) r2 ar2 star(* 0.1 ** 0.05 *** 0.01) nogap

*异质性
eststo clear
eststo:reghdfe $y $x $control  if SOE==0,absorb(id year) vce(cluster id)
eststo:reghdfe $y $x $control  if SOE==1,absorb(id year) vce(cluster id)
esttab  using 异质性.rtf, replace b(3) r2 ar2 star(* 0.1 ** 0.05 *** 0.01) nogap




使用道具

你好请问你解决了吗

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 13:41