用PSM方法两次了,早想记录这一语句了,迟到但到!先记录这一个,看后期会不会用到PSM-DID这一语句,就继续更。
直接上语句

///PSM
ssc install psmatch2
help psmatch2
psmatch2 D x1 x2 x3,outcome(y1)logit ties ate common odds
/*D是处理变量(分组变量),x估计概率的变量——看文献,哪些因素会影响参与培训,outcome指定结果变量——y1,Logit模型*/
psmatch2 D x1 x2 x3,outcome(y1)logit ties ate common odds
/*ties包括所有倾向得分相同的并列个体*/
psmatch2 D x1 x2 x3,outcome(y1)logit ties ate common odds
/*ate表示同时汇报ATE(参与者平均处理效应)、ATU(未参与者平均处理效应)、默认只汇报ATT(整体样本平均处理效应)*/
/*common表示对共同取值范围内个体进行匹配,默认对所有个体进行匹配*/
/*odd表示使用几率比,即p/(1-p)进行匹配,默认使用倾向性得分p进行匹配*/
*最近邻匹配(0.7-0.70001样本-n是邻匹配
psmatch2 D x1 x2 x3,outcome(y1)logit n(neighbor)(k)
*k写1就是一对一匹配,
*noreplacement(norepl):无放回匹配,只限于1:1匹配;
psmatch2 D x1 x2 x3,outcome(y1)logit n(k)
noreplacement caliper(0.05)
*区间内找,界限内,离个体值太大
*半径匹配
psmatch2 D x1 x2 x3,outcome(y1)radius caliper(0.05)
psmatch2 D x1 x2 x3,outcome(y1)kernel kerneltype(type) bwidth(real)
///默认使用二次核,默认宽带为0.06
举个例子————1.16
webuse nlswork,clear
gen age2 = age^2
gen ttl_exp2 = ttl_exp^2
gen tenure2 = tenure^2
global xlist"grade age age2 ttl exp ttl exp2 tenure tenure2 not smsa south race"
*定义种子
set seed 0001
*生成随机数
gen randomorder = runiform()
*将数据库随机排序
sort randomorder 
gen treated =(idcode > 2000) &! missing (idcode)
psmatch2 treated $xlist,out(ln_wage)logit ate neighbor(1)common caliper(.05)ties
*用pstest检查是否较好的平衡了结果
pstest $xlist, both graph
*图形显示共同取值范围
psgragh
webuse nlswork
//使用系统自带数据库
xtset idcode year,delta(1)
//设置面板
xtdescribe
//描述一下这个面板数据情况
gen age2= age^2
gen ttl_exp2-ttl_exp^2
gen tenure2=tenure^2
global xlist"grade age age2 ttl exp ttl_exp2 tenure tenure2 not smsa south race"
sum In_w $xlist
//统计描述相关变量
gen time =(year >=77)&!missing(year)
//政策执行时间为1977年
gen treated =(idcode >2000)&!missing(idcode) 
//政策执行地方为idcode大于2000
gen did = time*treated
//这就是需要估计的DID,也就所交叉项
set seed 0001
//定义种子
gen tmp = runiform()
//生成随机数
sort tmp
//把数据库随机整理
psmatch2 treated $xlist,out(ln_w)logit ate neighbor(1)common caliper(.05)ties
//通过近邻匹配,这里可以要outcome,也可以不要它
pstest $xlist,both graph
//检验协变量在处理组与控制组之间是否平衡
gen common = support
*drop if common ==0
//去掉不满足共同区域假定的观测值
*drop_weight==0
//也有情况是把没有匹配的直接删除
set seed 0001
//定义种子
gen tmp = runiform()
//生成随机数
sort tmp
//把数据库随机整理
psmatch2 treated $xlist,out(ln_w)logit ate neighbor(1)common caliper(.05)ties
//通过近邻匹配这里可以要outcome,也可以不要它
pstest $xlist,both graph
//检验协变量在处理组与控制组之间是否平衡
drop if_weight==.
//也有情况是把没有匹配的直接删除
xtreg ln_w did time treated $xlist.year,fe
drop if weight ==.
reg In_wage grade age age2 ttl_exp ttl_exp2 tenure tenure2 not_smsa south race 
reg In_wage grade age age2 ttl exp ttl_exp2 tenure tenure2 not_smsa south race if weight!=.
*卡尺最近邻匹配
*何瑛,于文蕾,杨棉之.CEO复合型职业经历、企业风险承担与企业价值[J].中国工业经济,2019(9).
*何靖延付高管薪酬对银行风险承担的政策效应-基于银行盈余管理动机视角的PSM-DID分析[J].

还有一个画图

 twoway                                                 ///
		  (kdensity _pscore if care==1, lp(solid) lw(*1.5))      ///
          (kdensity _pscore if care==0, lp(dash) lw(*1.5)),      ///
		  title("Before matching")                             ///
          ytitle("Kernel density") ylabel(,angle(0))                  ///
          xtitle("Propensity score") xscale(titlegap(2))       ///
          xlabel(0(0.2)1, format(%2.1f))                       ///
          legend(label(1 "Control group") label(2 "Treatment group") row(2)    ///
                 position(11) ring(0))                          ///
          scheme(s2color)   // 彩色图片 scheme(s2color) 
	  *-匹配后的密度函数图		 
	    twoway                                                   ///
		  (kdensity _pscore if _treated==1,lp(solid) lw(*1.5))         ///
          (kdensity _pscore if _treated==0&_wei!=.,lp(dash) lw(*1.5)), ///
	       title("After matching")                             ///
          ytitle("Kernel density") ylabel(,angle(0))                  ///
          xtitle("Propensity score") xscale(titlegap(2))       ///
          xlabel(0(0.2)1, format(%2.1f))                       ///
          legend(label(1 "Control group") label(2 "Treatment group") row(2) ///
                 position(11) ring(0))                          ///
          scheme(s2color)   // 彩色图片 scheme(s2color) 

先把代码写上,后续再修订。

用PSM方法两次了,早想记录这一语句了,迟到但到!先记录这一个,看后期会不会用到PSM-DID这一语句,就继续更。直接上语句///PSMssc install psmatch2help psmatch2psmatch2 D x1 x2 x3,outcome(y1)logit ties ate common odds/*D是处理变量(分组变量),x估计概率的变量——看文献,哪些因素会影响参与培训,outcome指定结果变量——y1,Logit模型*/psmatch2 D x1 x2 x3,ou
Stata,你可以使用"propensity score matching" (PSM) 实现逐期匹配。下面是一个例子代码: // 假设你有一个名为data的数据集,其的treatment变量代表治疗状态, // 并且你想要通过PSM找到控制组与实验组的匹配对: // 首先,你需要计算每个单位的估计propensity score: logit treatment x1 x2 x3 x4,...
gen temp=runiform() sort temp //计算倾向评分并为处理组找到相应的对照。psmatch2 因变量 协变量。除吸烟外,匹配其他变量达到均衡,目的是为探讨吸烟与q101的关系。out(q101)指明结局变量。neighbor是指处理组匹配的对照的个数,1:1配比法,因而在此选1。caliper是本例所用的卡钳值。noreplacement是指不重复利用对照。 // 年龄和bmi 连续 psmatch2...
目录1.安装psmatch2统计包。2.数据准备3.数据分析及命令解读4.结果解读4.1模型拟合结果,此处无太多实际意义。4.2试验组可匹配的观测概览,按照命令设定的匹配规则,试验组有8例患者未能匹配到合适对照。4.3结果解读的重点应该是对stata新生成的间变量的解读。4.4均衡性检验结果4.5匹配结果的图示化5.Stata命令汇总最后留下两个问题给大家思考:题目 试验设计,匹配的目的在于确保干预效应估计是建立在可比个体之间的不同结果的基础上。最简单的匹配方式是将干预组和对照组协变量值相同的两个个
windows + apache(服务器) + MySQL(数据库) + php引擎 wamp文件夹里边bin文件夹和www文件夹 bin: 里边存放的是Apache, php mysql的配置文件 www: 里边存放的是所有的php文件 也可以存放html css js 三.php的运行原理 四.写php文件 第一步:打开wamp集成环境 W必须是绿色才能正常运行 W有三种颜色: