As far as I can tell, there's no way to get this with pscore
(from SJC) directly. In some cases this is pretty easy to do by hand. For example, for nearest neighbor matching with replacement, it is just the closest untreated observation in terms of the propensity score. In general, for most types of matching the weights that determine the exact counterfactual for observation $i$ are pretty involved, so knowing which observations are "matched" is not very useful since this does not tell you the weights or allow you to calculate the treatment effects as it is not binary. Your kernel PSM would be one such case. Most PSM commands handle this calculation for you.
However, Stata's own teffects psmatch
has a generate(stub)
option. This will store the observation numbers of the nearest neighbors in new variables stub1, stub2, ..., stubk.
psmatch2
(from SSC) stores the same info under _n1,..,_nk for one-to-one and nearest-neighbors matching.
Here's an example using a dataset that everyone has access to (which is much better than using your own, which only you have) with 1 nearest neighbor:
webuse cattaneo2, clear
gen id = _n
sort id
teffects psmatch (bweight) (mbsmoke mmarried mage medu fbaby), gen(match) atet nn(1)
// Y1 and Y0 for everyone
generate bweight_1 = bweight if mbsmoke==1
generate bweight_0 = bweight if mbsmoke==0
replace bweight_1 = bweight[match1[_n]] if mbsmoke==0
replace bweight_0 = bweight[match1[_n]] if mbsmoke==1
gen id_of_first_match = id[match1[_n]]
// Show the counterfactual for first observation
list id* mbsmoke match1 bweight* if inlist(id,1,2729), noobs ab(20)
If we peek at the first observation and its single match, we get:
+---------------------------------------------------------------------------------+
| id id_of_first_match mbsmoke match1 bweight bweight_1 bweight_0 |
|---------------------------------------------------------------------------------|
| 1 2729 nonsmoker 2729 3459 3330 3459 |
| 2729 67 smoker 67 3330 3330 3686 |
+---------------------------------------------------------------------------------+
Here id 1 is getting matched to id 2729, so the unobserved birthweight-if-mother-smoked Y1 of id 1 would be 3330 grams. Baby 2729 is getting matched with id 67, and his unobserved birthweight-if-mother-not-smoked would be Y0 of 3686 grams.
Note that the number of match_X variables generated may be more than one neighbor because of tied PS scores. Most will be empty.
Best Answer
You evaluate the quality of matches after Mahlanobis distance matching exactly the same as you would after propensity score matching: by assessing balance on the covariates and ensuring the effective sample size of the matched sample is adequate. The form of matching has nothing to do with how balance is assessed. The propensity score is not relevant for balance assessment and is only a heuristic for assessing overlap and therefore is not at all necessary for evaluating matches.
If your question is about actually how to write a Stata command to do that, that is a programming problem, not a statistics problem, that should be asked on StackOverflow.