Dear Statalisters,
I am stuck with the following problem. I have data of the following form:
where group is a dummy stating the affiliation of an observation to a certain group and xvar1 as well as xvar2 are continous measures. Now, for each observation of Group 1 I would like to know the three observations of Group 0 which are closest in terms of the euclidean distance computed over xvar1 and xvar2.
A simple R code tells me that for observation 1 these are observations 5,6 and 10.
Now, I would like to tell Stata to keep only those observations of Group 0 that are matched with Group 1 observations. Does anyone have an idea how I can achieve this in Stata? I used teffects nnmatch but this does not work for more than the maximum of observations in Group 1 and also estimates ATE or ATT which my exercise isn't about -- I only want my sample to be constrained to matching observations before I do further analyses. In addition to my question, is there also a chance to control for replacement/no replacement?
Any help is highly appreciated!
I am stuck with the following problem. I have data of the following form:
Code:
input id group xvar1 xvar2 1 1 0 1 2 1 0.5 1.2 3 0 0 1.9 4 0 0.25 1.3 5 0 0.15 1.1 6 0 0.1 0.7 7 0 0.6 1.7 8 0 0.8 0.5 9 0 0.5 0.8 10 0 0.8 1 end
A simple R code tells me that for observation 1 these are observations 5,6 and 10.
Code:
x <- matrix(c(0, 1, 0.5, 1.2, 0, 1.9, 0.25, 1.3, 0.15, 1.1, 0.1, 0.7,
0.6, 1.7, 0.8, 0.5, 0.5, 0.8, 0.8, 1), ncol=2, byrow=TRUE)
dist <- dist(x, method = "euclidean", diag = TRUE, upper = FALSE, p = 2)
dist
Any help is highly appreciated!

Comment