本文主要包括倾向匹配得分命令简介、语法格式、倾向匹配得分操作步骤思路,涉及倾向匹配得分应用、平衡性检验、共同取值范围检验、核密度函数图等内容。 1:hr命令简介 Statadoesnothaveabuiltincommandforpropensityscorematching,anonexperimentalmethodofsamplingthatproducesacontrolgroupwhosedistributionofcovariatesissimilartothatofthetreatedgroup。However,thereareseveraluserwrittenmodulesforthismethod。Thefollowingmodulesareamongthemostpopular: Stata没有一个内置的倾向评分匹配的命令,一种非实验性的抽样方法,它产生一个控制组,它的协变量分布与被处理组的分布相似。但是,这个方法有几个用户编写的模块。以下是最受欢迎的模块(主要有如下几个外部命令) psmatch2。ado pscore。ado nnmatch。ado psmatch2。adowasdevelopedbyLeuvenandSianesi(2003)andpscore。adobyBeckerandIchino(2002)。Morerecently,Abadie,Drukker,Herr,andImbens(2004)introducednnmatch。ado。Allthreemodulessupportpairmatchingaswellassubclassification。 Youcanfindthesemodulesusingthe。netcommandasfollows: netsearchpsmatch2 netsearchpscore netsearchnnmatch Youcaninstallthesemodulesusingthe。sscor。netcommand,forexample: sscinstallpsmatch2,replace Afterinstallation,readthehelpfilestofindthecorrectusage,forexample: helppsmatch2 上述主要介绍了如何获得PSM相关的命令,总结一下目前市面上用的较好的命令为psmatch2。 PSM相关命令 helppsmatch2 helpnnmatch helppsmatch helppscore 持续获取最新的PSM信息和程序 finditpropensityscore finditmatching psmatch2isbeingcontinuouslyimprovedanddeveloped。Makesuretokeepyourversionuptodateasfollows sscinstallpsmatch2,replace whereyoucancheckyourversionasfollows: whichpsmatch2 2:hr语法格式 语法格式为: helppsmatch2 psmatch2depvar〔indepvars〕〔ifexp〕〔inrange〕〔,outcome(varlist)pscore(varname)neighbor(integer)radiuscaliper(real)mahalanobis(varlist)ai(integer)populationaltvariancekernelllrkerneltype(type)bwidth(real)splinenknots(integer)commontrim(real)noreplacementdescendingoddsindexlogittiesquietlyw(matrix)ate〕 选项含义为: depvar因变量; indepvars表示协变量; outcome(varlist)表示结果变量; logit指定使用logit模型进行拟合,默认的是probit模型; neighbor(1)指定按照1:1进行匹配,如果要按照1:3进行匹配,则设定为neighbor(3); radius表示半径匹配 核匹配(Kernelmatching) 其他匹配方法 广义精确匹配(CoarsenedExactMatching)helpcem 局部线性回归匹配(Locallinearregressionmatching) 样条匹配(Splinematching) 马氏匹配(Mahalanobismatching) pstestX,both做匹配前后的均衡性检验,理论上说此处只能对连续变量做均衡性检验,对分类变量的均衡性检验应该重新整理数据后运用2检验或者秩和检验。但此处对于分类变量也有一定的参考价值。 psgraph对匹配的结果进行图示。 3:hr案例应用 政策背景:国家支持工作示范项目(NationalSupportedWork,NSW) 研究目的:检验接受该项目(培训)与不接受该项目(培训)对工资的影响。基本思想:分析接受培训组(处理组,treatmentgroup)接受培训行为与不接受培训行为在工资表现上的差异。但是,现实可以观测到的是处理组接受培训的事实,而处理组没有接受培训会怎样是不可能观测到的,这种状态也成为反事实(counterfactual)。 匹配法就是为了解决这种不可观测事实的方法。在倾向得分匹配方法(PropensityScoreMatching)中,根据处理指示变量将样本分为两个组,一是处理组,在本例中就是在NSW实施后接受培训的组;二是对照组(comparisongroup),在本例中就是在NSW实施后不接受培训的组。倾向得分匹配方法的基本思想是,在处理组和对照组样本通过一定的方式匹配后,在其他条件完全相同的情况下,通过接受培训的组(处理组)与不接受培训的组(对照组)在工资表现上的差异来判断接受培训的行为与工资之间的因果关系。 1、首先进行数据结构查看 useldwexper。dta,cleareddesc 结果为: 2、描述性分析 tabulatet,summarize(re78)meansstandard 结果为: 3、倾向匹配得分 3。1首先进行排序,生成随机数种子 setseed20180105产生随机数种子genuruniform()sortu排序或者orderu 3。2倾向匹配得分 localv1tlocalv2ageedublackhispmarriedre74re75u74u75globalxv1v2 psmatch2x,out(re78)neighbor(1)atetieslogitcommon1:1匹配表示引用宏变量, 等价于psmatch2tageedublackhispmarriedre74re75u74u75,out(re78)neighbor(1)atetieslogitcommon 结果为: 3。3查看匹配后数据 结果为: 打开数据编辑窗口,会发现软件自动生成了几个新变量: 其中pscore是每个观测值对应的倾向值; id是自动生成的每一个观测对象唯一的ID(事实上这列变量即是对pscore排序); treated表示某个对象是否试验组; n1表示的是他被匹配到的对照对象的id(如果是1:3匹配,还会生成n2,n3); pdif表示一组匹配了的观察对象他们概率值的差。 3。4均衡性检验 pstestv2,bothgraph 结果为: 3。5共同取值范围 psgraph 结果为: 3。6核密度函数图 twoway(kdensitypsiftreat1,legend(label(1Treat)))(kdensitypsiftreat0,legend(label(2Control))),xtitle(Pscoreamp;gt;)title(BeforeMatching) 。twoway(kdensitypsiftreat1,legend(label(1Treat)))(kdensitypsif(weight!1amp;amp;weight!。),legend(label(2Control))),amp;gt;xtitle(Pscore)title(AfterMatching) 结果为: