【综合文库】
倾向得分匹配法(PSM)举例及stata实现
——读书笔记
【例】培训对工资的效应1
政策背景:国家支持工作示范项目(National Supported Work,NSW) 研究目的:检验接受该项目(培训)与不接受该项目(培训)对工资的影响。 基本思想:分析接受培训组(处理组,treatment group)接受培训行为与不接受培训行为在工资表现上的差异。但是,现实可以观测到的是处理组接受培训的事实,而处理组没有接受培训会怎样是不可能观测到的,这种状态也成为反事实(counterfactual)。匹配法就是为了解决这种不可观测事实的方法。在倾向得分匹配方法(Propensity Score Matching)中,根据处理指示变量将样本分为两个组,一是处理组,在本例中就是在NSW实施后接受培训的组;二是对照组(comparison group),在本例中就是在NSW实施后不接受培训的组。倾向得分匹配方法的基本思想是,在处理组和对照组样本通过一定的方式匹配后,在其他条件完全相同的情况下,通过接受培训的组(处理组)与不接受培训的组(对照组)在工资表现上的差异来判断接受培训的行为与工资之间的因果关系。
变量定义:
变量
定义
处理指示变量,1表示接受培训(处理组),0表示没有接受培训(对照组)年龄(年) 受教育年数(年)
种族虚拟变量,黑人时,BLACK=1 民族虚拟变量,西班牙人时,HSIP=1 婚姻状况虚拟变量,已婚,MARR=1
TREAT*
AGE EDUC BLACK
HSIP
MARR
RE74 1974年实际工资(1982年美元)
RE75 1975年实际工资
RE78 1978年实际工资 U74
当在1974年失业,U74=1 当在1975年失业,U75=1
U75 AGESQ
1
NODEGREE 当EDUC<12时,NODEGREE=1,否则为0
AGE×AGE
本例选自Cameron&Trivedi《微观计量经济学:方法与应用》(中译本,上海财经大学出版社,2022)pp794-800 所有数据及程序均来自于本书的配套网站(http://cameron.econ.ucdavis.edu/mmabook/mmaprograms.html)。本文是末学向两位善知识Cameron和Trivedi的教材恭敬学习后整理的读书笔记,没有任何创意,只是简化整理一番而已,整理中难免错谬之处,敬请指正,不胜感激。末学联系方式houhh1125@163.com
1
EDUCSQ EDUC×EDUC
RE74SQ RE75SQ
U74HSIP
RE74×RE74
RE75×RE75
U74×HSIP
U74BLACK U74×BLACK
*说明:1974、1975年NSW计划还没有实施,1978年NSW计划已经实施,如果1974、1975年的样本在NSW计划实施后接受了培训计划,那么TREAT
=1,否则TREAT=0,1978年的样本亦然。
按处理组分类统计 【stata command】
. bysort TREAT: sum AGE EDUC NODEGREE BLACK HISP MARR U74 U75 RE74 RE75 RE78 TREAT
变量
均值
处理组
对照组
AGE 25.81622 34.8506 EDUC 10.34595 12.11687 NODEGREE .7081081 .3052209 BLACK .8432432 .2506024 HISP .0594595 .0325301 MARR .1891892 .8662651 U74 .7081081 .0863454 U75 .6 .1 RE74 2022.574 19428.75 RE75 1532.056 19063.34 RE78 6349.145 21553.92 TREAT 1 0 培训对工资的效应影响有很多种估计方法,作者列举了五种方法,分别是:
TREATMENT-CONTROL COMPARISON(处理-对照比较法) CONTROL FUNCTION ESTIMATOR(控制函数估计量) DIFFERENCE-IN-DIFFERENCES(差异中差分法或倍差法) BEFORE-AFTER COMPARISON(前后比较法) propensity scores with matching(倾向得分匹配法)
2
其中倾向得分匹配法的stata实现过程如下:
总的讲来分为两大部分:一是为倾向打分,二是运用得分进行样本匹配并比较。
由于stata11没有倾向得分匹配法相关的命令,所以要通过网络下载相关的命令,相关的内容见附录。
一、倾向打分
第一步:设定宏变量breps表示重复抽样200次 . global breps 200
第二步,设定宏变量XDW02,表示变量AGE AGESQ EDUC EDUCSQ
MARR NODEGREE BLACK HISP RE74 RE75 RE74SQ U74 U75 U74HISP
. global XDW02 AGE AGESQ EDUC EDUCSQ MARR NODEGREE BLACK HISP RE74 RE75 RE74SQ U74 U75 U74HISP
第三步,通过logit模型进行倾向打分
. pscore TREAT $XDW02, pscore(myscore) comsup blockid(myblock) numblo(5) level(0.005) logit
【注释】$表示引用宏变量。
【注意】一定要把处理指示变量放在最前面 【options相关说明】
pscore(newvar) is required and asks users to specify the variable name for the estimated propensity score, which is added to the dataset.
blockid(newvar) allows users to specify the variable name for the block number of the estimated propensity score, which is added to the dataset.
logit uses a logit model to estimate the propensity score instead of thedefault probit model
comsup restricts the analysis of the balancing property to all treated plusthose controls in the region of common support. A dummy variable namedcomsup is added to the dataset to identify the observations in the commonsupport.
level(real) allows to set the significance level of the tests of the balancingproperty.The default is 0.01.
numblo(real) allows to set the number of blocks of equal score range to be used at the beginning of the test of the balancing hypothesis. The defaultis set to 5
3
blocks.
相关的结果参见stata窗口,总之这一步估计出了三个东西,一是myscore(Estimated propensity score);二是myblock(Number of block);三是comsup(Dummy for obs. in common support)
第四步,作者在do文件中说道:For completeness do same with common
support option NOT selected,相关命令如下:
. drop myscore myblock
. pscore TREAT $XDW02, pscore(myscore) blockid(myblock) numblo(5) level(0.005) logit
至此,倾向打分结束。接下来是根据倾向得分运用各种方法估计ATT值。
二、运用得分进行样本匹配并比较
方法一:Nearest neighbor matching (random version) 最邻近方法 首先,产生随机数种子
. set seed 10101 然后
. attnd RE78 TREAT $XDW02, comsup boot reps($breps) dots logit
【说明】注意变量排列次序,RE78正是我们所关心的变量,放在最前面;其次是处理指示变量,最后是其他变量。关于选项内容,使用help attnd命令可以详细学习。
通过stata结果窗口可看到有三张表格: 第一张表格
处理组样本数 对照组样本数
ATT* 标准差**
T统计量
185 60 1285.782 3895.044 0.330 *ATT(ATET)表示已处理的平均处理效应(average treatment effect on the treated) ** Analytical standard errors
第三张表格
4
处理组样本数 对照组样本数ATT 标准差***
T统计量
185 60 1285.782 1283.764 1.002 ***Bootstrapped standard errors
第一张表与第三张表的差别在于标准差的估计,第一张表使用的是解析标准差,第三张表使用自助法得到标准差。当然t统计量也随之发生变化。
方法二:Radius matching(半径匹配法)
. set seed 10101
. attr RE78 TREAT $XDW02, comsup boot reps($breps) dots logit radius(0.001)
【说明】选项radius( ),括号内填写半径值,例如0.1,0.5,0.00001等,本同样也需要注意变量排列次序问题,RE78正是我们所关心例的半径值为0.001。
的变量,放在最前面;其次是处理指示变量,最后是其他变量。另外,关于选项内容,使用help attr命令可以详细学习。
通过stata结果窗口可看到有三张表格,表格结构与最邻近方法类似。 方法三:Stratification Matching(分成匹配法)
. set seed 10101
. atts RE78 TREAT, pscore(myscore) blockid(myblock) comsup boot reps($breps) dots
方法四:Kernel Matching(核匹配方法)
. set seed 10101
. attk RE78 TREAT $XDW02, comsup boot reps($breps) dots logit
附录:pscore, attk, attnd, attnw, attr, atts 相关命令下载
第一步:查询
在stata命令窗口中点击 . findit pscore
第二步:点击链接
SJ-5-3st0026_2. . . . . . . . . . . . . . Software update for pscore suite . . . . . . . . . . . . . . . . . . . . . . S. O. Becker and A. Ichino (help attk, attnd, attnw, attr, atts, and pscore if installed) Q3/05 SJ 5(3):470
5
bug fix for pscore 第三步:点击下载链接
------------------------------------------------------------------------------ package st0026_2 from http://www.stata-journal.com/software/sj5-3 ------------------------------------------------------------------------------
TITLE
SJ5-3 st0026_2.Estimation of average treatment effects
DESCRIPTION/AUTHOR(S)
Estimation of average treatment effects by Sascha O. Becker, University of MunichAndrea Ichino, EUI Support:so.b@gmx.net, andrea.ichino@iue.it After installation, type help attk, attnd, attnw,attr, atts, and pscore
INSTALLATION FILES st0026_2/attk.ado st0026_2/attk.hlp st0026_2/attnd.ado st0026_2/attnd.hlp st0026_2/attnw.ado st0026_2/attnw.hlp st0026_2/attr.ado st0026_2/attr.hlp st0026_2/atts.ado st0026_2/atts.hlp st0026_2/pscore.hlp st0026_2/pscore.ado
6
(click here to install)
查看全文
false