其他
免费公开课--DID专题视频(论文精讲--传统DID、PSM-DID、平行趋势检验、安慰剂检验汇总)
来源:数量经济技术经济研究《专利质押、融资约束与企业劳动雇佣》
本文方法主题:DID模型
使用到了DID模型 平行趋势检验 安慰剂检验方法 PSM-DID 随机抽样1000次绘制安慰剂检验图
使用到的主要命令:
描述结果输出lxhsum 相关分析系数输出lxhcorr 结果输出lxhreg 平行趋势检验绘图eventdd DID模型分析命令xtreg PSM-DID分析中涉及到psmatch2、pstest
第一部分:双重差分知识回顾
第二部分:双重差分代码实现
* --------------------------------------------------
*
* $$$$$ $$$$$$$$ $ $$$$$$$$ $
* $$ $$ $ $$ $ $$ $ $$ $ $$
* $$ $ $$ $$$ $$ $$$
* $$$ $$ $ $$ $$ $ $$
* $$$ $$ $ $$ $$ $ $$
* $$$ $$ $$$$$ $$ $$$$$
* $ $$ $$ $ $$ $$ $ $$
* $$ $$ $$ $ $$ $$ $ $$
* $$$$$ $$$$ $$$ $$$$ $$$$ $$$ $$$$
*
* --------------------------------------------------
*
*
*-------------------------------------------------------------------------------
* 参考资料:
* 《初级计量经济学及Stata应用:Stata从入门到进阶》
* 《高级计量经济学及Stata应用:Stata回归分析与应用》
* 《量化社会科学方法》
* 《社会科学因果推断》
* 《面板数据计量分析方法》
* 《时间序列计量分析方法》
* 《高级计量经济学及Eviews应用》
* 《R、Python、Mtalab初高级教程》
* 《空间计量入门:空间计量在Geoda、GeodaSpace中的应用》
* 《零基础|轻松搞定空间计量:空间计量及GeoDa、Stata应用》
* 《空间计量第二部:空间计量及Matlab应用课程》
* 《空间计量第三部:空间计量及Stata应用课程》
* 《空间计量第四部:《空间计量及ArcGis应用课程》
* 《空间计量第五部:空间计量经济学》
* 《空间计量第六部:《空间计量及Python应用》
* 《空间计量第七部:《空间计量及R应用》
* 《空间计量第八部:《高级空间计量经济学》
*-------------------------------------------------------------------------------
* ==================================================
* 双重差分方法:DID专题
* ==================================================
*--------------------------------------------------------
**# *-> 案例6、数量经济技术经济研究--2022年第9期
**# *-> 论文复刻:专利质押、融资约束与企业劳动雇佣.pdf
*--------------------------------------------------------
**# 1、导入数据
cd C:\Users\Metrics\Desktop\DID专题
use 数据.dta, clear
global c "Size Lev Roa Soe p_GDP Second_ind "
**# 2、描述性统计-表2(P7页)
lxhsum Labor Hlabor Policy $c using 描述性统计.rtf, ///
replace s(N mean(%13.3f) sd(%13.3f) min(%13.3f) median(%13.3f) max(%13.3f))
拓展知识点:
描述结果输出lxhsum 相关分析系数输出(lxhcorr) 结果输出(lxhreg)
* 拓展知识、描述性统计输出(lxhsum)
* 命令语法:
lxhsum [varlist] [if] [in] [using/] [, ///
replace append Statistics(string) TItle(string) Alignment(string) PAGE(string)]
* 选项说明:
* varlist
* using
* replace
* append
* statistics():可以输入的全部统计量有:N mean sd min median max p1 p5 p10 p25 p75 p90 p95 p99。
* 若为空,则默认输入N mean sd min median max。
* title():表格标题,若为空,则默认为Summary statistics。
sysuse "auto.dta", clear //打开auto美国1978年汽车行业横截面数据
reg price mpg
lxhsum
lxhsum price mpg
lxhsum price mpg, s(N sd(3) min(%9.2f) p99(%9.3fc))
lxhsum price mpg, s(N sd(3) min(%9.2f) p99(%9.3fc)) ti(this is a title)
lxhsum price mpg using Tabls1.rtf, replace s(N sd(3) min(%9.2f) ) ti(this is a title)
**# 2、相关分析系数输出(lxhcorr)
lxhcorr [varlist] [if] [in] [using/] [, ///
replace append B(string) P(string) STARAUX NOSTAR ///
CORR PWCORR TItle(string) Alignment(string) PAGE(string) ]
* varlist:
* using:
* replace:
* append:含义同上。
* staraux和nostar:
* corr和pwcorr:
* 选项corr表示报告的相关系数与corr默认状态下一致(在计算相关系数前会先去除包含缺漏值的观察值);
* 选项pwcorr表示报告的相关系数与pwcorr默认状态下一致(在计算相关系数前不会先删除包含缺漏值);若两者均为空,则默认导入corr。
sysuse "auto.dta", clear //打开auto美国1978年汽车行业横截面数据
reg price mpg
lxhcorr
lxhcorr price mpg
lxhcorr price mpg, b(2)
lxhcorr price mpg, b(2) p(%9.3f)
lxhcorr price mpg, b(2) p(%9.3f) staraux
lxhcorr price mpg, b(2) p(%9.3f) nostar
lxhcorr price mpg, b(2) p(%9.3f) corr
lxhcorr price mpg, b(2) p(%9.3f) ti(this is a title)
lxhcorr price mpg using Myfile.rtf, replace b(2) p(%9.3f)
**# 3、结果输出(lxhreg)
**# 3、基准回归分析--**********3.1基准回归-表3**********(P8页)
use 数据, clear
xtset code year
qui xtreg Labor Policy i.year,fe vce(cluster code) // 不带控制变量 //
est store m1
qui xtreg Labor Policy $c i.year ,fe vce(cluster code)
est store m2
qui xtreg Hlabor Policy i.year ,fe vce(cluster code)
est store m3
qui xtreg Hlabor Policy $c i.year ,fe vce(cluster code)
est store m4
lxhreg m1 m2 m3 m4 using 基准回归结果1.rtf, replace t(%13.3f) b(%13.3f) drop( *year* )
* est_store_names:
* using:含义同上。
* replace:含义同上。
* append:含义同上。
* drop():不报告输入变量的系数;drop(_cons)表示不需要报告常数项。
* keep():
* varlabels():
基准回归
**# 3、基准回归分析--**********3.1基准回归-表3**********(P8页)
use 数据, clear
xtset code year
qui xtreg Labor Policy i.year,fe vce(cluster code) // 不带控制变量 //
est store m1
qui xtreg Labor Policy $c i.year ,fe vce(cluster code)
est store m2
qui xtreg Hlabor Policy i.year ,fe vce(cluster code)
est store m3
qui xtreg Hlabor Policy $c i.year ,fe vce(cluster code)
est store m4
lxhreg m1 m2 m3 m4 using 基准回归结果1.rtf, replace t(%13.3f)b(%13.3f) drop( *year* )
DID有效性检验与其他稳健性测试
**# 4、**********3.2 DID有效性检验与其他稳健性测试**********
************平行趋势检验-图2******
use 数据,clear
xtset code year
replace Policy_year=. if Policy_year==0
gen yeardif=year-Policy_year
xtset code year
eventdd Labor $c i.year, timevar(yeardif) method(fe) cluster(code) level(95) baseline(0) ///
graph_op( yline(0,lcolor(edkblue*0.8) ) ///
xlabel(-6 "- 6" -5 "- 5" -4 "- 4" -3 "- 3" -2 "-2" -1 "-1" 0 "0" 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6") ///
ylabel(-0.1(0.1)0.4,format (%7.1f)) ///
xline(0 ,lwidth(vthin) lpattern(dash) lcolor(teal)) ///
xtitle(`"{fontface "宋体": 政策时点}"', size(medium small)) ///
ytitle(`"{fontface "宋体": 回归系数}{stSerif: (Labor)}"', size(medium small)) ///
legend(order(2 `"{fontface "宋体": 回归系数}"' 1 "95% confidence interval" )) scheme(s1mono))
graph export "平行趋势Labor.png", replace
eventdd Hlabor $c i.year, timevar(yeardif) method(fe) cluster(code) level(95) baseline(0) ///
graph_op( yline(0,lcolor(edkblue*0.8) ) ///
xlabel(-6 "- 6" -5 "- 5" -4 "- 4" -3 "- 3" -2 "-2" -1 "-1" 0 "0" 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6") ///
ylabel(-0.2(0.2)1,format (%7.1f)) ///
xline(0 ,lwidth(vthin) lpattern(dash) lcolor(teal)) ///
xtitle(`"{fontface "宋体": 政策时点}"', size(medium small)) ///
ytitle(`"{fontface "宋体": 回归系数}{stSerif: (HLabor)}"', size(medium small)) ///
legend(order(2 `"{fontface "宋体": 回归系数}"' 1 "95% confidence interval" )) scheme(s1mono))
graph export "平行趋势HLabor.png", replace
预期效应与政策外生性检验
**# 5、**********************预期效应与政策外生性检验-表4***********
***********预期效应-表4(1)-(2)******
use 数据, clear
replace Policy_year=. if Policy_year==0
gen Policy_psy=Policy_year-1
gen Policy_pre1=0
replace Policy_pre1=1 if year==Policy_psy & Treat==1
xtset code year
qui xtreg Labor Policy Policy_pre1 $c i.year, fe vce(cluster code)
est store m1
qui xtreg Hlabor Policy Policy_pre1 $c i.year, fe vce(cluster code)
est store m2
lxhreg m1 m2 using 预期效应pre1.rtf,replace t(%13.3f)b(%13.3f) drop (*year*)
********保留政策前样本——政策时点替换为2007年表4(3)-(4)***********
use 数据,clear
keep if year<=2007
gen Policy_ps=0
replace Policy_ps=1 if Treat==1 & year==2007
qui xtreg Labor Policy_ps $c i.year,fe vce(cluster code)
est store m1
qui xtreg Hlabor Policy_ps $c i.year,fe vce(cluster code)
est store m2
lxhreg m1 m2 using 预期效应置换政策2007.rtf,replace t(%13.3f)b(%13.3f) drop (*year*)
***政策随机性——生存分析(接受政策时点的时间长短)表4(5)-(6)***********
use 数据, clear
replace Policy_year=2015 if Policy_year==0
bys code : gen count=_N
drop if count<11 /*drop 8362 obs*/
gen dif1=Policy_year-year
// replace dif =5 if treat==0
drop if dif1<0
gen poo=0
replace poo=1 if dif1==0
gen yearcs=2005
stset year, id(code) failure(poo==1) origin(yearcs)
xi:stcox Labor $c , nohr
est store model
xi:stcox Hlabor $c , nohr
est store model1
lxhreg model model1 using cox生存分析.rtf, replace t(%13.3f)b(%13.3f)
6、安慰剂检验(随机系数法)
**# 6、安慰剂检验(随机系数法)
***************安慰剂检验(随机系数法)-图2(a)、(b)*************
use 数据,clear
duplicates drop code,force
bro code year if Treat==1 // 591个企业被定义为实验组,将用于被挑选//
*-删除临时文件
forvalue i=1/1000{
erase placebo`i'.dta
}
clear
set matsize 500
* 系数矩阵
mat b = J(500,1,0)
* 标准误矩阵
mat se = J(500,1,0)
* P值矩阵
mat t = J(500,1,0)
forvalues i=1/500{
* 循环1000次
use 数据,clear
duplicates drop code,force
sample 591, count
keep code
cap drop u
gen u = uniform()
sort u
drop u
gen j=_n
save matchidt, replace
use 数据,clear
sample 591, count //随机抽取591企业样本
keep year //得到所抽取样本的id编号
cap drop u
gen u = uniform()
sort u
drop u
gen j=_n
save matchidy, replace
merge 1:1 j using matchidt
drop j _m
rename year yearrandom
merge 1:m code using regress
replace Treat = (_merge == 3)
gen Postrandom=0
replace Postrandom=1 if year>yearrandom
tostring year ,replace
//gen feffect=substr(indcd,1,2)+substr(year,1,4)
//egen effect=group(feffect)
destring year,replace
global c "Size Lev Roa Soe p_GDP Second_ind "
gen Policy1 = Treat*postrandom
xtset code year
qui xtreg Labor Policy1 $c i.year , fe vce(cluster code)
g _b_random_rep78= _b[Policy1] //提取x的回归系数
g _se_random_rep78= _se[Policy1] //提取x的标准误
qui xtreg Hlabor Policy1 $c i.year , fe vce(cluster code)
g _b_random1_rep78= _b[Policy1] //提取x的回归系数
g _se_random1_rep78= _se[Policy1] //提取x的标准误
keep _b_random_rep78 _se_random_rep78 _b_random1_rep78 _se_random1_rep78
duplicates drop _b_random_rep78 _b_random1_rep78, force
save placebo`i', replace
}
*- 纵向合并1000次的系数和标准误
use placebo1, clear
forvalue i=2/500{
append using placebo`i' //纵向合并1000次回归的系数及标准误
}
gen tvalue= _b_random_rep78/ _se_random_rep78
gen p2=2*ttail(2910, abs(tvalue))
gen tvalue1= _b_random1_rep78/ _se_random1_rep78
gen p21=2*ttail(2910, abs(tvalue1))
twoway (scatter p2 _b_random_rep78 ,yaxis(1) xline( 0.145, lwidth(0.3) lp(solid)) ///
xlabel(-0.10(0.05)0.15, format(%7.2f) grid) xtitle(Coefficient) ytitle(P value) ylabel(0(0.5)2, format(%7.2f)axis(1) gmin angle(horizontal)) ///
yline(0.1, lwidth(0.2) lp(shortdash) ) ///
msymbol(smcircle_hollow) msize(tiny) legend(off)) (kdensity _b_random_rep78 ,yaxis(2) ytitle("Density",axis(2)) ylabel(0(2)10, axis(2) gmin angle(horizontal))scheme(s1mono) )
graph export "安慰剂检验1.png", replace
twoway (scatter p21 _b_random1_rep78 ,yaxis(1) xline( 0.228, lwidth(0.3) lp(solid)) ///
xlabel(-0.2(0.1)0.3, format(%7.1f) grid) xtitle(Coefficient) ytitle(P value) ylabel(0(0.5)2, format(%7.2f) axis(1) gmin angle(horizontal)) ///
yline(0.1, lwidth(0.2) lp(shortdash) ) ///
msymbol(smcircle_hollow) msize(tiny) legend(off)) (kdensity _b_random1_rep78 ,yaxis(2) ytitle("Density",axis(2)) ylabel(0(1)5, axis(2) gmin angle(horizontal))scheme(s1mono))
graph export "安慰剂检验2.png", replace
*******安慰剂检验(事件年前推一年两年)-附录表A2********
use 数据,clear
gen Policy_current=0
replace Policy_current=1 if b2008==1 & year>2008
gen Policy_pre1=0
replace Policy_pre1=1 if b2008==1 & year>2007
gen Policy_pre2=0
replace Policy_pre2=1 if b2008==1 & yea>2006
replace Policy_current=1 if b2009==1 & year>2009
replace Policy_pre1=1 if b2009==1 & year>2008
replace Policy_pre2=1 if b2009==1 & year>2007
replace Policy_current=1 if b2010==1 & yea>2010
replace Policy_pre1=1 if b2010==1 & year>2009
replace Policy_pre2=1 if b2010==1 & year>2008
keep if year<2011
xtset code year
qui xtreg Labor Policy_pre1 $c i.year,fe vce(cluster code)
est store m1
qui xtreg Hlabor Policy_pre1 $c i.year,fe vce(cluster code)
est store m2
qui xtreg Labor Policy_pre2 $c i.year,fe vce(cluster code)
est store m3
qui xtreg Hlabor Policy_pre2 $c i.year,fe vce(cluster code)
est store m4
lxhreg m1 m2 m3 m4 using 前推一年两年安慰剂.rtf,replace t(%13.3f)b(%13.3f) drop (*year*)
PSM--DID分析
**# 7、PSM--DID分析
**************PSM-DID估计-表5*****************
use 数据,clear
preserve
keep if year==2007
drop if b2009==1|b2010==1
save sample2007,replace
restore
preserve
keep if year==2008
drop if b2008==1|b2010==1
save sample2008,replace
restore
preserve
keep if year==2009
drop if b2008==1|b2009==1
save sample2009,replace
restore
*******1:3匹配*********
use sample2007,clear
global c "Size Lev Roa Soe p_GDP Second_ind "
cap drop u
gen u = uniform()
sort u
psmatch2 Treat $c, common n(3) qui
pstest, both
******核密度图——共同支撑检验-见附录图A1*****
//-(a)before matching: 匹配前的密度函数图//
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0,lp(dash) lw(*2.5)), ///
ytitle("Density") ///
ylabel(,angle(0)) ///
xtitle("Propensity Score") ///
xscale(titlegap(2)) ///
xlabel(0(0.05)0.3, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "核密度2007pre.png", replace
*-(b)after matching: 匹配后的密度函数图
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0&_wei!=.,lp(dash) lw(*2.5)), ///
ytitle("Density") ylabel(,angle(0)) ///
xtitle("Propensity Score") xscale(titlegap(2)) ///
xlabel(0(0.05)0.3, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "核密度2007post.png", replace
save ps2007,replace
keep if _weight !=.
save psm2007,replace
use sample2008,clear
cap drop u
gen u = uniform()
sort u
psmatch2 Treat $c , common n(3) qui
pstest, both
******核密度图——共同支撑检验-附录图A2*****
//-(a)before matching: 匹配前的密度函数图//
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0,lp(dash) lw(*2.5)), ///
ytitle("Density") ///
ylabel(,angle(0)) ///
xtitle("Propensity Score") ///
xscale(titlegap(2)) ///
xlabel(0(0.05)0.25, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "核密度2008pre.png", replace
*-(b)after matching: 匹配后的密度函数图
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0&_wei!=.,lp(dash) lw(*2.5)), ///
ytitle("Density") ylabel(,angle(0)) ///
xtitle("Propensity Score") xscale(titlegap(2)) ///
xlabel(0(0.05)0.25, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "核密度2008post.png", replace
save ps2008,replace
keep if _weight !=.
save psm2008,replace
use sample2009,clear
cap drop u
gen u = uniform()
sort u
psmatch2 Treat $c, common n(3) qui
pstest, both
******核密度图——共同支撑检验-附录图A3*****
//-(a)before matching: 匹配前的密度函数图//
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0,lp(dash) lw(*2.5)), ///
ytitle("Density") ///
ylabel(,angle(0)) ///
xtitle("Propensity Score") ///
xscale(titlegap(2)) ///
xlabel(0(0.1)0.6, format(%7.1f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "核密度2009pre.png", replace
*-(b)after matching: 匹配后的密度函数图
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0&_wei!=.,lp(dash) lw(*2.5)), ///
ytitle("Density") ylabel(,angle(0)) ///
xtitle("Propensity Score") xscale(titlegap(2)) ///
xlabel(0(0.1)0.5, format(%7.1f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "核密度2009post.png", replace
save ps2009,replace
keep if _weight !=.
save psm2009,replace
use psm2007,clear
append using psm2008
append using psm2009
duplicates drop code,force
keep code
save psmpipei3,replace
**# 8、PSM--DID分析
**********PSM-DID1:3估计-表5(1)-(2)列*******
use 数据,clear
merge m:1 code using psmpipei3
keep if _m==3
drop _merge
global c "Size Lev Roa Soe p_GDP Second_ind"
xtset code year
qui xtreg Labor Policy $c i.year ,fe vce(cluster code)
est store ind1
qui xtreg Hlabor Policy $c i.year ,fe vce(cluster code)
est store ind2
lxhreg ind1 ind2 using psm1比3.rtf,replace t(%13.3f)b(%13.3f) drop( *year* )
**************PSM1:5***********
use sample2007,clear
global c "Size Lev Roa Soe p_GDP Second_ind "
cap drop u
gen u = uniform()
sort u
psmatch2 Treat $c, common n(5) qui
pstest, both
******核密度图——共同支撑检验-附录图A4*****
//-(a)before matching: 匹配前的密度函数图//
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0,lp(dash) lw(*2.5)), ///
ytitle("Density") ///
ylabel(,angle(0)) ///
xtitle("Propensity Score") ///
xscale(titlegap(2)) ///
xlabel(0(0.05)0.3, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "psm1比5核密度2007pre.png", replace
*-(b)after matching: 匹配后的密度函数图
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0&_wei!=.,lp(dash) lw(*2.5)), ///
ytitle("Density") ylabel(,angle(0)) ///
xtitle("Propensity Score") xscale(titlegap(2)) ///
xlabel(0(0.05)0.3, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "psm1比5核密度2007post.png", replace
save ps52007,replace
keep if _weight !=.
save psm52007,replace
use sample2008,clear
cap drop u
gen u = uniform()
sort u
psmatch2 Treat $c , common n(5) qui
pstest, both
******核密度图——共同支撑检验-附录图A5*****
//-(a)before matching: 匹配前的密度函数图//
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0,lp(dash) lw(*2.5)), ///
ytitle("Density") ///
ylabel(,angle(0)) ///
xtitle("Propensity Score") ///
xscale(titlegap(2)) ///
xlabel(0(0.05)0.25, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "psm1比5核密度2008pre.png", replace
*-(b)after matching: 匹配后的密度函数图
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0&_wei!=.,lp(dash) lw(*2.5)), ///
ytitle("Density") ylabel(,angle(0)) ///
xtitle("Propensity Score") xscale(titlegap(2)) ///
xlabel(0(0.05)0.25, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "psm5核密度2008post.png", replace
save ps52008,replace
keep if _weight !=.
save psm52008,replace
use sample2009,clear
cap drop u
gen u = uniform()
sort u
psmatch2 Treat $c, common n(5) qui
pstest, both
******核密度图——共同支撑检验-附录图A6*****
//-(a)before matching: 匹配前的密度函数图//
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0,lp(dash) lw(*2.5)), ///
ytitle("Density") ///
ylabel(,angle(0)) ///
xtitle("Propensity Score") ///
xscale(titlegap(2)) ///
xlabel(0(0.1)0.6, format(%7.1f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "核密度2009pre.png", replace
*-(b)after matching: 匹配后的密度函数图
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0&_wei!=.,lp(dash) lw(*2.5)), ///
ytitle("Density") ylabel(,angle(0)) ///
xtitle("Propensity Score") xscale(titlegap(2)) ///
xlabel(0(0.1)0.5, format(%7.1f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "核密度2009post.png", replace
save ps52009,replace
keep if _weight !=.
save psm52009,replace
use psm52007,clear
append using psm52008
append using psm52009
duplicates drop code,force
keep code
save psmpipei5,replace
**********PSM-DID1:5估计-表5(3)-(4)列*******
use 数据,clear
merge m:1 code using psmpipei5
keep if _m==3
drop _merge
global c "Size Lev Roa Soe p_GDP Second_ind "
xtset code year
qui xtreg Labor Policy $c i.year ,fe vce(cluster code)
est store ind1
qui xtreg Hlabor Policy $c i.year ,fe vce(cluster code)
est store ind2
lxhreg ind1 ind2 using psm1比5.rtf,replace t(%13.3f)b(%13.3f) drop( *year* )
*********************全样本PSM匹配——附录表A9-A10***********
************1:3******
use 数据,clear
global c "Size Lev Roa Soe p_GDP Second_ind "
cap drop u
gen u = uniform()
sort u
psmatch2 Treat $c, common n(3) qui
pstest, both
******核密度图——共同支撑检验-附录图A7*****
//-(a)before matching: 匹配前的密度函数图//
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0,lp(dash) lw(*2.5)), ///
ytitle("Density") ///
ylabel(,angle(0)) ///
xtitle("Propensity Score") ///
xscale(titlegap(2)) ///
xlabel(0(0.1)0.6, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "psm1比3核密度全样本pre.png", replace
*-(b)after matching: 匹配后的密度函数图
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0&_wei!=.,lp(dash) lw(*2.5)), ///
ytitle("Density") ylabel(,angle(0)) ///
xtitle("Propensity Score") xscale(titlegap(2)) ///
xlabel(0(0.1)0.5, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "psm1比3核密度全样本post.png", replace
save ps3quan,replace
keep if _weight !=.
save psm3quan,replace
********************全样本1:3匹配PSM-DID估计-附录表A11(1)-(2)*****
use psm3quan, clear
global c "Size Lev Roa Soe p_GDP Second_ind "
xtset code year
qui xtreg Labor Policy $c i.year ,fe vce(cluster code)
est store ind1
qui xtreg Hlabor Policy $c i.year ,fe vce(cluster code)
est store ind2
lxhreg ind1 ind2 using psm1比31.rtf,replace t(%13.3f)b(%13.3f) drop( *year* )
************1:5*********
use 数据,clear
global c "Size Lev Roa Soe p_GDP Second_ind "
cap drop u
gen u = uniform()
sort u
psmatch2 Treat $c, common n(5) qui
pstest, both
******核密度图——共同支撑检验-附录图A8*****
//-(a)before matching: 匹配前的密度函数图//
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0,lp(dash) lw(*2.5)), ///
ytitle("Density") ///
ylabel(,angle(0)) ///
xtitle("Propensity Score") ///
xscale(titlegap(2)) ///
xlabel(0(0.1)0.6, format(%7.2f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "psm1比5核密度全样本pre.png", replace
*-(b)after matching: 匹配后的密度函数图
twoway (kdensity _pscore if _treat==1,lp(solid) lw(*2.5)) ///
(kdensity _pscore if _treat==0&_wei!=.,lp(dash) lw(*2.5)), ///
ytitle("Density") ylabel(,angle(0)) ///
xtitle("Propensity Score") xscale(titlegap(2)) ///
xlabel(0(0.1)0.5, format(%7.1f)) ///
legend(label(1 "treat") label(2 "control") row(2) ///
position(3) ring(0)) ///
scheme(s1mono)
graph export "psm1比5核密度全样本post.png", replace
save ps5quan,replace
keep if _weight !=.
save psm5quan,replace
********************全样本1:5匹配PSM-DID估计-附录表A11(3)-(4)*****
use psm5quan, clear
global c "Size Lev Roa Soe p_GDP Second_ind "
xtset code year
qui xtreg labor policy $c i.year ,fe vce(cluster code)
est store ind1
qui xtreg hlabor policy $c i.year ,fe vce(cluster code)
est store ind2
lxhreg ind1 ind2 using psm1比51.rtf,replace t(%13.3f)b(%13.3f) drop( *year* )
更多内容请查看《数量经济技术经济研究》