stata中的psm语句

您所在的位置:网站首页 面板数据did检验stata语句 stata中的psm语句

stata中的psm语句

2024-02-25 20:56| 来源: 网络整理| 查看: 265

用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)

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



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3