matching_weights: Unit weights implied by matching

View source: R/matching_weights.R

matching_weightsR Documentation

Unit weights implied by matching

Description

matching_weights derives the weights implied by a matching for units assigned to matched groups. If the matching is exact, reweighting the units with this function will produce a sample where all treatment groups are identical on the matching covariates. If the matching is approximate but of good quality, the reweighted treatment groups will be close to identical.

Usage

matching_weights(treatments, matching, target = NULL)

Arguments

treatments

factor specifying the units' treatment assignments.

matching

qm_matching or scclust object with the matched groups.

target

units to target the weights for. If NULL, the weights will target all units, so that the reweighted treatment groups are as similar as possible to the complete sample (i.e., corresponding to ATE). A non-null value specifies a subset of units that the weights should be targeted for (e.g., ATT or ATC). If target is a logical vector with the same length as the sample size, units indicated with TRUE will be targeted. If target is an integer vector, the units with indices in target are targeted. If target is a character vector, it should contain treatment labels, and the weights target the corresponding units (as given by treatments).

Details

Let S(g) be the number of units indicated by target in group g (or the total number of units in the group if target is NULL). Let T be the total number of units indicated by target in the sample (or the sample size if target is NULL). Let A(t, g) be the number of units assigned to treatment t in group g. The weight for a unit in group g that is assigned to treatment t is given by:

\frac{S(g)}{T \times A(t, g)}.

Consider, for example, a matched group with one treated unit and two control units when we are interested in the average effect of the treated (ATT) and we have 50 treated units in total (T=50). For all three units in the group, we have S(g)=1. For the treated unit we have A(t, g)=1, so its weight becomes 1/50. The two control units have A(t, g)=2, so their weights are both 1/100.

These weights are such that the difference between the weighted averages of the outcomes in two treatment conditions is the same as the average within-group difference-in-means between the two conditions.

If a matched group g with S(g) > 0 lacks some treatment condition t, no weights exist for the units assigned to t (in other groups) so to replicate group g; the matching does not contain enough information to impute the missing treatment in group g. Subsequently, all units assigned to t will be given the weight NA. There is two ways to solve this problem. First, one can change the target estimand by setting S(g) = 0 for all groups that are missing units assigned to t. This is done with the target parameter. Second, one can change the matching so that all groups contain at least one unit assigned to t (e.g., by merging groups).

Units not assigned to matched groups are given zero weights.

Value

Returns a numeric vector with the weights of the units in the matching.

Examples

# Construct example data
my_data <- data.frame(y = rnorm(100),
                      x1 = runif(100),
                      x2 = runif(100),
                      treatment = factor(sample(rep(c("T1", "T2", "C"), c(25, 25, 50)))))

# Make distances
my_distances <- distances(my_data, dist_variables = c("x1", "x2"))

# Make matching
my_matching <- quickmatch(my_distances, my_data$treatment)

# Weights for ATE
weights_ate <- matching_weights(my_data$treatment, my_matching)

# Weights for ATT for T1
weights_att <- matching_weights(my_data$treatment, my_matching, target = "T1")

# Estimate treatment effects with WLS estimator (see `lm_match`)
effects <- lm(y ~ treatment + x1 + x2, data = my_data, weights = weights_att)


quickmatch documentation built on Sept. 11, 2024, 7:55 p.m.