Stata:偏差校正倾向得分匹配及PSM操作应用
计量经济学服务中心专辑汇总!计量百科·资源·干货: Stata |Python |Matlab |Eviews |R Geoda |ArcGis |GeodaSpace |SPSS 一文读懂 |数据资源 |回归方法 |网络爬虫 门限回归 |工具变量 |内生性 |空间计量 因果推断 |合成控制法 |倾向匹配得分 |断点回归 |双重差分 面板数据 | 动态面板数据
一.命令介绍
偏差校正倾向得分匹配方法对应命令为:nnmatch
语法格式为:
nnmatch depvar treatvar varlist_nnmatch [if exp] [in range] [pw] [, tc(ate |att |atc) m(#) metric(maha |matname) exact(varlist_ex) biasadj(bias |varlist_adj) robust(#_v) population level(#) keep(filename) replace]
详细解释为:
depvar :结果变量
treatvar:处理变量
varlist_nnmatch :匹配变量
tc(ate|att|atc) specifies which treatment effect is to be estimated:
ate: the average treatment effect,
att: the average treatment effect for the treated, or
atc: the average treatment effect for the controls.
metric(maha |matname) :metric(maha)表示使用马氏距离,即权重矩阵为样本协方差矩阵的逆矩阵
m(#) :进行#近邻匹配,默认#=1。
robust(#_v):表示进行异方差稳健的标准误
Example:
nnmatch y t x1 x2
nnmatch y t x1, m(3)
nnmatch y t x1 x2, tc(att)
nnmatch y t x1 x2, tc(atc) met(maha) bias(bias) robust(4)
nnmatch y t x1 x2, met(matname) bias(x1 x3) keep(artdata) replace
nnmatch y t x1 x2 [w=w], met(matname) bias(x1 x3) exact(x4) pop
二.偏差校正匹配估计量操作应用
本文仍然使用倾向得分匹配所对应的案例数据,所对应的变量数据结构为:
首先使用一对一的匹配,不做偏差校正,但是进行稳健标准误估计:
nnmatch re78 t age edu black his married re74 re75 u74 u75, tc(atc) m(1) robust(1)
上表显示权重矩阵为默认的,即对角线元素为各变量样本方差的对角矩阵之逆矩阵,ATT的估计值为2.2624,并且在5%的水平下显著
下面进行进行偏差校正
nnmatch re78 t age edu black his married re74 re75 u74 u75, tc(atc) m(1) robust(1) bias(bias)
发现atc的值减少到2.1603,并且也在5%显著性水平下显著
下面使用样本协方差矩阵的逆矩阵为权重矩阵,metric(maha)即使用马氏距离
nnmatch re78 t age edu black his married re74 re75 u74 u75, tc(atc) m(1) robust(1) bias(bias) metric(maha)
结构为:
大家都在读:一文读懂倾向得分匹配法(PSM)举例及stata实现(一)
一、倾向匹配得分应用之培训对工资的效应
政策背景:国家支持工作示范项目( National Supported Work,NSW )
研究目的:检验接受该项目(培训)与不接受该项目(培训)对工资的影响。基本思想:分析接受培训组(处理组, treatment group )接受培训行为与不接受培训行为在工资表现上的差异。但是,现实可以观测到的是处理组接受培训的事实,而处理组没有接受培训会怎样是不可能观测到的,这种状态也成为反事实( counterfactual )。
匹配法就是为了解决这种不可观测事实的方法。在倾向得分匹配方法( Propensity Score Matching )中,根据处理指示变量将样本分为两个 组,一是处理组,在本例中就是在 NSW 实施后接受培训的组;二是对照组 ( comparison group ),在本例中就是在 NSW 实施后不接受培训的组。倾向得分 匹配方法的基本思想是,在处理组和对照组样本通过一定的方式匹配后,在其他 条件完全相同的情况下,通过接受培训的组(处理组)与不接受培训的组(对照 组)在工资表现上的差异来判断接受培训的行为与工资之间的因果关系。
注:本例节选自 Cameron&Trivedi 《微观计量经济学:方法与应用》(中译本,上海财经大学出版社, 2010 ) pp794-800 所有数据及程序均来自于本书的配套网站( http://cameron.econ.ucdavis.edu/mmabook/mmaprograms.html )。
二、变量介绍
描述性分析
tabulate t, summarize(re78) means standard
结果为:
三、倾向匹配得分操作
数据介绍 :Data used by Lalonde (1986)We are interested in the possible effect of participation in a job training program on individuals earnings in 1978This dataset has been used by many authors ( Abadie et al. 2004,Becker and Ichino, 2002, Dehejia and Wahba, 1999).
四、详细介绍
set seed 20180105 //产生随机数种子
gen u=runiform()
sort u //排序
或者order u
上述命令是为了生成伪随机数,满足01的均匀分布
local v1 "t"
local v2 "age edu black hisp married re74 re75 u74 u75"
global x "`v1' `v2' "
psmatch2 $x, out(re78) neighbor(1) ate ties logit common // 1:1 匹配
$表示引用宏变量,
psmatch2 $x, out(re78) neighbor(1) ate ties logit common // 1:1 匹
等价于
psmatch2 t age edu black hisp married re74 re75 u74 u75, out(re78) neighbor(1) ate ties logit common
下面用pstest查看匹配效果是否较好的平衡了数据
psmatch2 t age edu black hisp married re74 re75 u74 u75, out(re78) neighbor(1) ate ties logit common // 1:1 匹
pstest age edu black hisp married re74 re75 u74 u75, both graph
psgraph
五、PSM命令简介
Stata does not have a built-in command for propensity score matching, a non-experimental method of sampling that produces a control group whose distribution of covariates is similar to that of the treated group. However, there are several user-written modules for this method. The following modules are among the most popular:
Stata没有一个内置的倾向评分匹配的命令,一种非实验性的抽样方法,它产生一个控制组,它的协变量分布与被处理组的分布相似。但是,这个方法有几个用户编写的模块。以下是最受欢迎的模块(主要有如下几个外部命令)
psmatch2.ado
pscore.ado
nnmatch.ado
psmatch2.ado was developed by Leuven and Sianesi (2003) and pscore.ado by Becker and Ichino (2002). More recently, Abadie, Drukker, Herr, and Imbens (2004) introduced nnmatch.ado. All three modules support pair-matching as well as subclassification.
You can find these modules using the .net command as follows:
net search psmatch2
net search pscore
net search nnmatch
You can install these modules using the .ssc or .net command, for example:
ssc install psmatch2, replace
After installation, read the help files to find the correct usage, for example:
help psmatch2
上述主要介绍了如何获得PSM相关的命令,总结一下目前市面上用的较好的命令为psmatch2.
PSM 相关命令
help psmatch2
help nnmatch
help psmatch
help pscore
持续获取最新的 PSM 信息和程序
findit propensity score
findit matching
psmatch2 is being continuously improved and developed. Make sure to keep your version up-to-date as follows
ssc install psmatch2, replace
where you can check your version as follows:
which psmatch2
语法格式
help psmatch2
psmatch2 depvar [indepvars] [if exp] [in range] [, outcome(varlist)
pscore(varname) neighbor(integer) radius caliper(real)
mahalanobis(varlist) ai(integer) population altvariance
kernel llr kerneltype(type) bwidth(real) spline
nknots(integer) common trim(real) noreplacement
descending odds index logit ties quietly w(matrix) ate]
where indepvars and mahalanobis(varlist) may contain factor variables;
see fvvarlist.
psmatch2 D x1 x2 x3, outcome(y)
pscore(varname) neighbor(integer) radius caliper(real)
mahalanobis(varlist) ai(integer) population altvariance
kernel llr kerneltype(type) bwidth(real) spline
nknots(integer) common trim(real) noreplacement
descending odds index logit ties quietly w(matrix) ate]
核匹配 (Kernel matching)
其他匹配方法
广义精确匹配(Coarsened Exact Matching) || help cem
局部线性回归匹配 (Local linear regression matching)
样条匹配 (Spline matching)
马氏匹配 (Mahalanobis matching)