问题:看了中工的论文代码还有一些公众号的文章,对于PSM匹配前后核密度曲线图中的匹配后的控制组数据的读取有疑惑。下面是中工的两篇文章截取的代码:
1、
*-(a)before matching: 匹配前的密度函数图
twoway (kdensity _ps if _treated==1,lp(solid) lw(*2.5)) ///
(kdensity _ps if _treated==0,lp(dash) lw(*2.5)), ///
ytitle("Density") ///
ylabel(,angle(0)) ///
xtitle("Propensity Score") ///
xscale(titlegap(2)) ///
xlabel(0(0.2)0.8, format(%2.1f)) ///
legend(label(1 "Treat") label(2 "Control") row(2) ///
position(12) ring(0)) ///
scheme(s1mono)
// graph export "01.wmf", replace fontface("Times New Roman")
graph save a1,replace
*-(b)after matching: 匹配后的密度函数图
twoway (kdensity _ps if _treated==1, lp(solid) lw(*2.5)) ///
(kdensity _ps if _treated==0&_wei!=.,lp(dash) lw(*2.5)), ///
ytitle("Density") ylabel(,angle(0)) ///
xtitle("Propensity Score") xscale(titlegap(2)) ///
xlabel(0(0.2)0.8, format(%2.1f)) ///
legend(label(1 "Treat") label(2 "Control") row(2) ///
position(12) ring(0)) ///
scheme(s1mono)
2、
*匹配前核密度图
twoway (kdensity _ps if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _ps if _treat==0,lp(dash) lw(*2.5)), ///
ytitle("Density", size(*1.1)) ///
ylabel(,angle(0) labsize(*1.1)) ///
xtitle("Propensity Score", size(*1.1)) ///
xscale(titlegap(2)) ///
xlabel(0(0.2)0.8, format(%2.1f) labsize(*1.1)) ///
legend(label(1 "Treatment Group") label(2 "Controls Group") row(2) ///
position(10) ring(0) size(*1.1)) ///
scheme(s1mono)
graph export "kn01_large.png", as(png)///
replace fontface("Times New Roman")
********************************
**附图2:匹配后P值得分核密度图**
********************************
*匹配后核密度图
twoway (kdensity _ps if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _ps if _wei!=1 & _wei!=.,lp(dash) lw(*2.5)), ///
ytitle("Density", size(*1.1)) ///
ylabel(,angle(0) labsize(*1.1)) ///
xtitle("Propensity Score", size(*1.1)) ///
xscale(titlegap(2)) ///
xlabel(0(0.2)0.8, format(%2.1f) labsize(*1.1)) ///
legend(label(1 "Treatment Group") label(2 "Controls Group") row(2) ///
position(10) ring(0) size(*1.1)) ///
scheme(s1mono)
graph export "kn02_large.png",as(png)///
replace fontface("Times New Roman")
重点在匹配后的图控制组的数据即_weight部分,一个是使用 (kdensity _ps if _treated==0&_wei!=.,lp(dash) lw(*2.5)), ///,一个是使用(kdensity _ps if _wei!=1 & _wei!=.,lp(dash) lw(*2.5)), ///;相当于_treated == 0和weight!=0是等价的,但是我用webuse nlswork数据看了一下这两个不等,不知道为啥会有这样的差异,求求大家解答了!