rnearest-neighborpropensity-score-matchingmatchit

Nearest Neighbor Matching in R using the built-in MatchIt-function


I'm trying to implement a simple nearest neighbor matching for bonds that matches bonds from a treatment group with certain characteristics to bonds from a control group with similar characteristics. For the distance I wanted to use the Mahanolobis distance. The bonds are supposed to be matched exact based on certain variables ('ticker' and 'currency') and within a specific range for certain other variables ('maturity' and 'issued_amount_USD'). More precise, the code should match one bond from the treatment group with two bonds from the control group with coinciding ticker and currency while the absolute distance in maturities should be smaller or equal than two years (one bond with earlier maturity and one bond with later maturity) and the distance in issued amount should be smaller or equal than 4x the issued amount of the matched treatment bond.

Is there a specific code that succeeds to implement that matching in the usual MatchIt function or another solution?

Thanks in advance!

To capture the latter, I planned to use the caliper of the MatchIt-function (see below). However, the standard caliper only refers to the standard deviations in distances and not to absolute variable values. Using "std.caliper = False" helps out to use absolute values, but I'm failing at implementing the presented range.

matches <- matchit(
  formula = treatment ~ ticker + issued_amount_USD + currency + maturity,
  data = bonds,
  method = 'nearest',
  distance = 'mahalanobis',
  ratio = 2,
  caliper = c(maturity = 730, issued_amount_USD = 500000000),
  std.caliper = FALSE,
  exact = c('ticker','currency'),
  discard = 'none'
)

Note: I used some arbitrary absolute values in caliper right now.


Solution

  • There is no way to require that one bond with earlier maturity and one bond with later maturity are matched to each treated bond. That would require a whole new matching algorithm. To my knowledge, no matching software allows that option.

    Setting std.caliper = FALSE does request unstandardized calipers, which is useful for your case. With that, you can supply the desired caliper for maturity in days as you have done.

    To implement a multiplicative caliper, you instead need to supply the log of the variable and the log of the caliper. So first you would create a new variable, bonds$log_issued_amount <- log(bonds$issued_amount_USD), then give that variable a caliper of log(4). Note that this will produce a symmetric caliper, i.e., a control bond can be neither 4 times the amount or .25 times the amount of the treated bond. There is no way to avoid this.

    In general, if a restriction you want to implement isn't available by default in MatchIt, you can always implement it yourself by first creating a distance matrix and then manually setting to Inf any distance that corresponds to two units that should not be allowed to be paired. You can then supply that distance matrix to the distance argument. mahalanobis_dist() creates a Mahalanobis distance matrix.