You can perform exact matching on some variables and distance matching on others. For example, you could request that all individuals are matched to another individual of the same sex who is closest to them on age. The R packages Matching
and MatchIt
allow this kind of matching through their exact
arguments. This can be a useful way to achieve exact balance on the exactly matched variables. Problems can occur when matching without replacement and there aren't enough control units to be matched with the treated units in a given category.
If you want exact balance on a categorical variable but don't necessarily want exact matches, you can also look into a form of matching called matching for fine balance. This form of matching ensures that the treatment and control groups have the same proportion of units in each category of the categorical variable without requiring that the same units are matched on another categorical variable. For example, if you have sex and race, exact matching would require white females to be matched with white females, etc. Matching for fine balance would simply require that the proportion of white individuals is the same in the treatment and control groups and the proportion of females is the same in the treatment and control groups. It's much easier to retain a larger matched sample with matching for fine balance than it is for exact matching. Note that you can perform matching for fine balance on some variables and distance matching on others (just like you could with exact matching). Matching for fine balance is available in the R package designmatch
, which is extremely flexible and also allows for distance and exact matching (and even other forms of matching). It relies on optimization so a single distance value doesn't need to be calculated.