How do you run matching sequentially on unmatched treated? [R]

42 Views Asked by At

I'd like to do exact matching as much as possible but without losing treated without a match. Below is an example of what I mean by sequential matching. Is this a good idea? A real world example would need to run this more often, and so I'm looking for a more efficient way to pack it into a function. How could this be generalized to N iterations until all matches are found?

library(MatchIt)
data(lalonde)

# Step 1: Perform the first matching with a set of exact variables (in this example age)
mout1 <- matchit(treat ~ age + educ + married + race + nodegree + re74 + re75, 
                 data = lalonde,
                 method = "nearest",
                 exact = ~ age,
                 ratio = 1)

summary(mout1)$nn
# Control Treated
# All (ESS)         429     185
# All               429     185
# Matched (ESS)     184     184
# Matched           184     184
# Unmatched         245       1
# Discarded           0       0

# Step 2: Identify the unmatched treated cases using match.data
full_matched_data <- match.data(mout1, drop.unmatched = FALSE)
unmatched_treated <- subset(full_matched_data, is.na(subclass) & treat == 1, 
                            select = -c(10:12)) |> as.data.frame()

# Step 3: Perform a second matching on the subset of unmatched cases with less restrictive criteria
mout2 <- matchit(treat ~ age + educ + married + race, 
                 data = rbind(unmatched_treated, subset(lalonde, treat == 0)), # combine unmatched treated with all control
                 method = "nearest",
                 ratio = 1) # no exact matching in the second step to make it less restrictive

# Combine the matched data from the first and second steps
combined_matched_data <- rbind(match.data(mout1), match.data(mout2))
0

There are 0 best solutions below