本文主要包括傾向匹配得分命令簡介、語法格式、傾向匹配得分操作步驟 思路,涉及傾向匹配得分應用、平衡性檢驗、共同取值範圍檢驗、核密度函數圖等內容。
1
命令簡介
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
2
語法格式
語法格式為:
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]選項含義為:
depvar因變量 ;
indepvars表示協變量;
outcome(varlist)表示結果變量;
logit指定使用logit模型進行擬合,默認的是probit模型;
neighbor(1)指定按照1:1進行匹配,如果要按照1:3進行匹配,則設定為neighbor(3);
radius表示半徑匹配
核匹配 (Kernel matching)
其他匹配方法
廣義精確匹配(Coarsened Exact Matching) || help cem
局部線性回歸匹配 (Local linear regression matching)
樣條匹配 (Spline matching)
馬氏匹配 (Mahalanobis matching)
pstest $X, both做匹配前後的均衡性檢驗,理論上說此處只能對連續變量做均衡性檢驗,對分類變量的均衡性檢驗應該重新整理數據後運用χ2檢驗或者秩和檢驗。但此處對於分類變量也有一定的參考價值。
psgraph對匹配的結果進行圖示。
3
案例應用
政策背景:國家支持工作示範項目( National Supported Work,NSW )
研究目的:檢驗接受該項目(培訓)與不接受該項目(培訓)對工資的影響。基本思想:分析接受培訓組(處理組, treatment group )接受培訓行為與不接受培訓行為在工資表現上的差異。但是,現實可以觀測到的是處理組接受培訓的事實,而處理組沒有接受培訓會怎樣是不可能觀測到的,這種狀態也成為反事實( counterfactual )。
匹配法就是為了解決這種不可觀測事實的方法。在傾向得分匹配方法( Propensity Score Matching )中,根據處理指示變量將樣本分為兩個 組,一是處理組,在本例中就是在 NSW 實施後接受培訓的組;二是對照組 ( comparison group ),在本例中就是在 NSW 實施後不接受培訓的組。傾向得分 匹配方法的基本思想是,在處理組和對照組樣本通過一定的方式匹配後,在其他 條件完全相同的情況下,通過接受培訓的組(處理組)與不接受培訓的組(對照組)在工資表現上的差異來判斷接受培訓的行為與工資之間的因果關係。
1、首先進行數據結構查看
use "ldw_exper.dta", clear eddesc結果為:
2、描述性分析
tabulate t, summarize(re78) means standard結果為:
3、傾向匹配得分
3.1 首先進行排序,生成隨機數種子
set seed 20180105 //產生隨機數種子 gen u=runiform() sort u //排序 或者 order u3.2 傾向匹配得分
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 $表示引用宏變量,
等價於 psmatch2 t age edu black hisp married re74 re75 u74 u75, out(re78) neighbor(1) ate ties logit common結果為:
3.3 查看匹配後數據
結果為:
打開數據編輯窗口,會發現軟體自動生成了幾個新變量:
其中_pscore是每個觀測值對應的傾向值;
_id是自動生成的每一個觀測對象唯一的ID(事實上這列變量即是對_pscore排序);
_treated表示某個對象是否試驗組;
_n1表示的是他被匹配到的對照對象的_id(如果是1:3匹配,還會生成_n2, _n3);
_pdif表示一組匹配了的觀察對象他們概率值的差。
3.4 均衡性檢驗
結果為:
3.5 共同取值範圍
結果為:
3.6 核密度函數圖
twoway(kdensity _ps if _treat==1,legend(label(1 "Treat")))(kdensity _ps if _treat==0, legend(label(2 "Control"))),xtitle(Pscore> ) title("Before Matching")
. twoway(kdensity _ps if _treat==1,legend(label(1 "Treat")))(kdensity _ps if (_weight!=1&_weight!=.), legend(label(2 "Control"))),> xtitle(Pscore) title("After Matching")結果為: