全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
23997 15
2016-05-03
看了stata中的help文件,说是teffects psmatch的基本语句是:
  teffects psmatch (ovar) (tvar tmvarlist [, tmodel]) [if] [in] [weight] [, stat
            options]

不大理解什么意思了,感觉与psmatch2语句差别很大。请教牛人, teffects psmatch 后面这些语句分别是输入什么东西?非常感谢!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-5-3 12:05:54
liuqianrui111 发表于 2016-5-3 11:39
看了stata中的help文件,说是teffects psmatch的基本语句是:
  teffects psmatch (ovar) (tvar tmvarlist ...
一般是teffects psmatch (y) (t x1 x2, probit), atet nn(#) caliper(#)

不选probit就默认logit, atet是显示ate on the treated, nn(#)里面的#表示1对#匹配,caliper表示卡尺内匹配#表示水平。teffects psmatcgh比之前的psmatch2的优点是提供了Abadie & Imbens(2012)的稳健标准误,其他的差不多。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-5-3 16:04:24
caimiao0714 发表于 2016-5-3 12:05
一般是teffects psmatch (y) (t x1 x2, probit), atet nn(#) caliper(#)

不选probit就默认logit, atet是 ...
非常感谢您,太详细了!请问t是不是就是赋值0 1的虚拟变量?1在处理组,0在对照组,跟psmatch2一样的?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-5-3 22:15:38
liuqianrui111 发表于 2016-5-3 16:04
非常感谢您,太详细了!请问t是不是就是赋值0 1的虚拟变量?1在处理组,0在对照组,跟psmatch2一样的?
客气了,是你所说的这样的,t指的是treatment,即你自己定义的分组。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-5-5 09:55:06
http://www.statalist.org/forums/forum/general-stata-discussion/general/1145219-psmatch2-graph-for-propensity-score-matching/page2

http://www.ssc.wisc.edu/sscc/pubs/stata_psmatch.htm

[size=14.399999618530273px]

这个帖子讲了在使用 PSM 时,stata官方命令和外部命令 psmatch2 如何配合使用。
最重要的是,说明了如何取出配对样本,这使得 DID+PSM 分析可以实操了。


http://www.ssc.wisc.edu/sscc/pubs/stata_psmatch.htm
Propensity Score Matching in Stata using teffects

For many years, the standard tool for propensity score matching in Stata has been the psmatch2 command, written by Edwin Leuven and Barbara Sianesi. However, Stata 13 introduced a new teffects command for estimating treatments effects in a variety of ways, including propensity score matching. The teffects psmatch command has one very important advantage over psmatch2: it takes into account the fact that propensity scores are estimated rather than known when calculating standard errors. This often turns out to make a significant difference, and sometimes in surprising ways. We thus strongly recommend switching from psmatch2 to teffects psmatch, and this article will help you make the transition.
An Example of Propensity Score Matching

Run the following command in Stata to load an example data set:
use http://ssc.wisc.edu/sscc/pubs/files/psm
It consists of four variables: a treatment indicator t, covariates x1 and x2, and an outcome y. This is constructed data, and the effect of the treatment is in fact a one unit increase in y. However, the probability of treatment is positively correlated with x1 and x2, and both x1 and x2 are positively correlated with y. Thus simply comparing the mean value of y for the treated and untreated groups badly overestimates the effect of treatment:
ttest y, by(t)
(Regressing y on t, x1, and x2 will give you a pretty good picture of the situation.)
The psmatch2 command will give you a much better estimate of the treatment effect:
psmatch2 t x1 x2, out(y)

You can carry out the same estimation with teffects. The basic syntax of the teffects command when used for propensity score matching is:
teffects psmatch (outcome) (treatmentcovariates)
In this case the basic command would be:
teffects psmatch (y) (t x1 x2)
However, the default behavior of teffects is not the same as psmatch2 so we'll need to use some options to get the same results. First, psmatch2 by default reports the average treatment effect on the treated (which it refers to as ATT). The teffects command by default reports the average treatment effect (ATE) but will calculate the average treatment effect on the treated (which it refers to as ATET) if given the atet option. Second, psmatch2 by default uses a probit model for the probability of treatment. The teffects command uses a logit model by default, but will use probit if the probit option is applied to the treatment equation. So to run the same model using teffects type:
teffects psmatch (y) (t x1 x2, probit), atet

The average treatment effect on the treated is identical, other than being rounded at a different place. But note that teffects reports a very different standard error (we'll discuss why that is shortly), plus a Z-statistic, p-value, and 95% confidence interval rather than just a T-statistic.
Running teffects with the default options gives the following:
teffects psmatch (y) (t x1 x2)

This is equivalent to:
psmatch2 t x1 x2, out(y) logit ate
----------------------------------------------------------------------------------------
        Variable     Sample |    Treated     Controls   Difference         S.E.   T-stat
----------------------------+-----------------------------------------------------------
               y  Unmatched |  1.8910736  -.423243358   2.31431696   .109094342    21.21
                        ATT |  1.8910736   .930722886   .960350715   .168252917     5.71
                        ATU |-.423243358   .625587554   1.04883091            .        .
                        ATE |                           1.01936701            .        .
----------------------------+-----------------------------------------------------------

The ATE from this model is very similar to the ATT/ATET from the previous model. But note that psmatch2 is reporting a somewhat different ATT in this model. The teffects command reports the same ATET if asked:
teffects psmatch (y) (t x1 x2), atet


Matching With Multiple Neighbors

By default teffects psmatch matches each observation with one other observation. You can change this with the nneighbor() (or just nn()) option. For example, you could match each observation with its three nearest neighbors with:
teffects psmatch (y) (t x1 x2), nn(3)

Start with a clean slate by typing:
use http://ssc.wisc.edu/sscc/pubs/files/psm, replace
The gen() option tells teffects psmatch to create a new variable (or variables). For each observation, this new variable will contain the number of the observation that observation was matched with. If there are ties or you told teffects psmatch to use multiple neighbors, then gen() will need to create multiple variables. Thus you supply the stem of the variable name, and teffects psmatch will add suffixes as needed.
teffects psmatch (y) (t x1 x2), gen(match)
In this case each observation is only matched with one other, so gen(match) only creates match1. Referring to the example output, the match of observation 1 is observation 467 (which is why those two are listed).
Note that these observation numbers are only valid in the current sort order, so make sure you can recreate that order if needed. If necessary, run:
gen ob=_n
and then:
sort ob
to restore the current sort order.
The predict command with the ps option creates two variables containing the propensity scores, or that observation's predicted probability of being in either the control group or the treated group:
predict ps0 ps1, ps
Here ps0 is the predicted probability of being in the control group (t=0) and ps1 is the predicted probability of being in the treated group (t=1). Observations 1 and 467 were matched because their propensity scores are very similar.
The po option creates variables containing the potential outcomes for each observation:
predict y0 y1, po
Because observation 1 is in the control group, y0 contains its observed value of y. y1 is the observed value of y for observation 1's match, observation 467. The propensity score matching estimator assumes that if observation 1 had been in the treated group its value of y would have been that of the observation in the treated group most similar to it (where "similarity" is measured by the difference in their propensity scores).
Observation 467 is in the treated group, so its value for y1 is its observed value of y while its value for y0 is the observed value of y for its match, observation 781.
Running the predict command with no options gives the treatment effect itself:
predict te
The treatment effect is simply the difference between y1 and y0. You could calculate the ATE yourself (but emphatically not its standard error) with:
sum te
and the ATET with:
sum te if t

Regression on the "Matched Sample"
We will discuss how to run regressions on a matched sample because it remains a popular technique, but we cannot recommend it.
psmatch2 makes it easy by creating a _weight variable automatically. For observations in the treated group, _weight is 1. For observations in the control group it is the number of observations from the treated group for which the observation is a match. If the observation is not a match, _weight is missing. _weight thus acts as a frequency weight (fweight) and can be used with Stata's standard weighting syntax. For example (starting with a clean slate again):
use http://ssc.wisc.edu/sscc/pubs/files/psm, replace
psmatch2 t x1 x2, out(y) logit
reg y x1 x2 t [fweight=_weight]

Observations with a missing value for _weight are omitted from the regression, so it is automatically limited to the matched sample. Again, keep in mind that the standard errors given by the reg command are incorrect because they do not take into account the matching stage.
teffects psmatch does not create a _weight variable, but it is possible to create one based on the match1 variable. Here is example code, with comments:
gen ob=_n //store the observation numbers for future use
save fulldata,replace // save the complete data set

keep if t // keep just the treated group
keep match1 // keep just the match1 variable (the observation numbers of their matches)
bysort match1: gen weight=_N // count how many times each control observation is a match
by match1: keep if _n==1 // keep just one row per control observation
ren match1 ob //rename for merging purposes

merge 1:m ob using fulldata // merge back into the full data
replace weight=1 if t // set weight to 1 for treated observations


The resulting weight variable will be identical to the _weight variable created by psmatch2, as can be verified with:
assert weight==_weight
It is used in the same way and will give exactly the same results:
reg y x1 x2 t [fweight=weight]
Obviously this is a good bit more work than using psmatch2.

Other Methods of Estimating Treatment Effects
While propensity score matching is the most common method of estimating treatment effects at the SSCC, teffects also implements Regression Adjustment (teffects ra), Inverse Probability Weighting (teffects ipw), Augmented Inverse Probability Weighting (teffects aipw), Inverse Probability Weighted Regression Adjustment (teffects ipwra), and Nearest Neighbor Matching (teffects nnmatch). The syntax is similar, though it varies whether you need to specify variables for the outcome model, the treatment model, or both:
teffects ra (y x1 x2) (t)
teffects ipw (y) (t x1 x2)
teffects aipw (y x1 x2) (t x1 x2)
teffects ipwra (y x1 x2) (t x1 x2)
teffects nnmatch (y x1 x2) (t)

Complete Example Code
复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-10-7 16:57:27
非常棒!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群