ans96
ans96

Reputation: 23

Using multiple calipers in R package Matching

I am attempting to use the Match function from the Matching package to create a matched dataset on 4 variables. I want two of these variables to be exact matches and two to be within a set range.

I have the following code:

X <- cbind(tmpcomb$sexf, tmpcomb$dobyear, tmpcomb$municipality_code, tmpcomb$first_test)
colnames(X) <- c("sex", "dobyear", "municipality", "test_date")
Tr <- tmpcomb$Tr

#Define caliper for age within 5 years (see package documentation for caliper)
cal_age <- 5/sd(tmpcomb$dobyear)
cal_test_date <- 180/sd(tmpcomb$first_test, na.rm = T)
  
#match
tmp_matched <- Match(Tr = Tr, X = X, exact = c(0, 1, 0, 1), caliper = c(.001, cal_age, .001,  cal_test_date))
summary(tmp_matched)

I want sex and municipality to be exact, dobyear to be within 5 years, and first_test to be within 180 days. I believe that what I have written in for caliper is incorrect, though, as it is only doing exact matches. Could someone please explain to me how to use caliper in this setting, I think I must be doing something incorrectly. Thanks!

Upvotes: 2

Views: 557

Answers (1)

Noah
Noah

Reputation: 4414

By setting exact = c(0, 1, 0, 1) you are requesting exact matching on the second and fourth variables in X, which are dobyear and test_date, and requesting that exact matching not be done on sex and municipality. The calipers for dobyear and test_date are ignored because you are requesting exact matching on them. Change exact to be exact = c(TRUE, FALSE, TRUE, FALSE) to ensure you are requesting exact matching on the correct variables. The caliper for the exactly matched variables will be ignored so you don't need to specify .001 for them (i.e., you can supply Inf and nothing will change).

Upvotes: 1

Related Questions