Skip to content
Ben edited this page Aug 2, 2017 · 2 revisions

Matching within calipers and subcategories

Matching on a scalar distance

The following first prepares a distance of 0s and Infs, indicating which pairs are of the same sex and within 2 years of one another in age, before going on to pair them up optimally.

dist <- exactMatch(casestatus~sex, data=mydata)
dist <- match_on(casestatus~age, method="euclidean", within=dist)
dist <- caliper(dist, width=2)
pairs <- pairmatch(casestatus~date, within=dist)

The method="euclidean" at the second line overrides the mahalanobis default, which would have had the effect of constraining the match to be within +/- 2 pooled sds of age, not +/- 2 years.

Matching on a Mahalanobis distance within calipers and subcategories

If within the calipers you wanted to match on date and age, rather than just date, you might instead end with the following. It'll combine date and age differences into a Mahalanobis distance.

pairs <- pairmatch(casestatus~ date + age, within=dist)

Further elaborations

You might also take a look at Implementing non-standard matching distances