Vivian
Vivian

Reputation: 309

propensity score matching in MatchIt package

I use the MatchIt package do the propenstiy score in matching

I want to know the "case" match to which "control", how do i do

for example, the first case match to the first control, second case match to the second control, and so on.

Upvotes: 1

Views: 1233

Answers (1)

Michelle H
Michelle H

Reputation: 21

I just had the same problem and found some syntax that can help.

First, after you open the data set but before you run MatchIt, use the following code (data is your data frame and ID is your identifer):

####set rownames to id.
rownames(data) <- data$ID
head(data)

Second, Run the appropriate matchit syntax into an object, like so:

M.OUT1 <- matchit(Treat ~ X1 + X2, data = data)

Third run the following code:

mm<-M.OUT1$match.matrix
tx<-as.numeric(row.names(mm))
m<-cbind(tx,as.numeric(mm))
m[1:5,]
View(m)
write_sav(data.frame(m),"MatchedPairs.sav")

The write_sav line can be modified to fit whatever you are exporting your data into (in my case, SPSS. The write_sav function requires the haven package)

Upvotes: 2

Related Questions