stata中的psm语句

用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 k(bwidth)
///默认使用二次核,默认宽带为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) 

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

  • 9
    点赞
  • 104
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Stata进行PSM(Propensity Score Matching)分析后,输出的结果通常包括匹配前和匹配后的结果。以下是一些常见的结果及其解释: 1. Treatment balance检验:该检验主要用于检验在匹配前,接受处理组和未接受处理组之间的差异是否显著。如果结果显示,在匹配前,两组之间存在显著差异,则说明接受处理组和未接受处理组之间的随机化并不充分,需要进行进一步的PSM分析。 2. 变量匹配质量:该指标用于评估在匹配后,接受处理组和未接受处理组之间是否已经实现了更好的匹配。如果匹配后,匹配变量在两组之间的差异较小,则说明匹配的质量较高。 3. ATT(平均处理效应)和ATE(平均处理效应):这两个指标是用来衡量处理效应的大小。ATT是针对接受处理组的,而ATE是针对总体样本的。如果ATT或ATE的值为正,则说明处理对结果有积极的影响,反之则说明处理对结果有负面的影响。 4. Matching Quality Metrics:这些指标主要用于评估匹配后,接受处理组和未接受处理组之间的匹配质量。其,Matching Quality Metrics包括标准差差异(SMD)、卡方值(χ²)和t-test等指标。如果匹配后,这些指标较小,则说明匹配的质量较高。 需要注意的是,PSM只是一种数据分析方法,其结果并不能完全代表因果关系。因此,在解读PSM结果时,需要谨慎对待,并结合实际情况进行综合分析。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值