全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
539 1
2023-10-17
DID 画图错误,有偿求指导,

egen city= group(cityid)

clear

set matsize 5000

cd"E:\stata-spatial\digitalin-frastructure-finance"

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 "inno_policy.dta", clear

    xtset city year

    keep if year==2016

    sample 96, count

    keep city

    save "atchcity.dta",replace

    merge 1:m city using "inno_policy.dta"

    gen groupnew=(_merge==3) //生成伪处理组的虚拟变量

    save "matchcity`i'.dta",replace


    *伪政策虚拟变量

    use "inno_policy.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/269 {

        replace time = 1 if (city == `j' & year >= sampleyear[`j',1])

    }   

    gen did1=time*groupnew

    global xlist  "x1 x2 x3 x4 x5 x6 x7 x8"   

    xtreg y1 did1  $xlist i.year, fe robust


    mat b[`i',1] = _b[did1]

    mat se[`i',1] = _se[did1]

    scalar df_r = e(N) - e(df_m) -1

    mat p[`i',1] = 2*ttail(df_r,abs(_b[did1]/_se[did1]))

}

svmat b, names(coef)

svmat se, names(se)

svmat p, names(pvalue)


drop if pvalue1 == .

label var pvalue1 p值

label var coef1 估计系数

saveplacebo.dta,replace  

forvalue i=1/500{

    erase "matchcity`i'.dta"

}

twoway(scatter pvaluecoef1,xlabel(-0.015(0.01)0.0155,grid) yline(0.1,lp(shortdash)) xline(1.5,lp(shortdash))xtitle(估计系数) ytitle(p值) msymbol(smcircle_hollow)mcolor(blue) legend(off))(kdensity coef1,title(安慰剂检验))


运行其中出错误的情况


898.png

最后图形

1.png



二维码

扫码加我 拉你入群

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

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

全部回复
2023-10-19 09:31:40
已解决,感谢论坛
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群