quickmatch (version 0.2.1)

covariate_averages: Covariate averages in matched sample

Description

covariate_averages derives covariate averages for treatment groups in matched samples.

Usage

covariate_averages(treatments, covariates, matching = NULL,
  target = NULL)

Value

Returns a matrix with the average of each covariate for each treatment group. The rows in the matrix correspond to the covariates in order and the columns correspond to the treatment groups. For example, a possible output with three treatment groups ("C", "T1" and "T2") and four covariates is:

CT1T2
3.03.33.5
-0.30.0-0.2
0.10.20.0
5.05.14.9

which indicates that the average of the first covariate in the matched sample is 3.0 for units assigned to condition "C", and that the average of the third covariate is 0.2 for units assigned to condition "T1".

Arguments

treatments

factor specifying the units' treatment assignments.

covariates

vector, matrix or data frame with covariates to calculate averages for.

matching

qm_matching or scclust object with the matched groups. If NULL, averages are derived for the unmatched sample.

target

units to target the averages for. If NULL, the averages will be the raw average over all units in the sample (i.e., ATE). A non-null value specifies a subset of units to derive averages 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 corresponding units (as given by treatments) will be targeted. If matching is NULL, target is ignored.

Details

covariate_averages calculates covariate averages by first deriving the average for each covariate for each treatment conditions in each matched group. It then aggregates the group averages by a weighted average, where the target parameter decides the weights. If a matched group contains many units not targeted (e.g., control units when ATT is of interest), those units will contribute less to the covariate average for the corresponding treatment condition than units in matched groups with many targeted units. This means that the covariate average is calculated in the same way as the potential outcomes are estimated. In fact, covariate_averages can be used as an estimator for potential outcomes by calling it with the outcome variable as a covariate.

When the average treatment effect (ATE) is of interest (i.e., target == NULL), the matched groups will be weighted by their sizes. When target indicates that some subset of units is of interest, the number of such units in each matched group will decide its weight. For example, if we are interested in the average treatment effect of the treated (ATT), the weight of a group will be proportional to the number of treated units in that group.

In practice, the function first derives the unit-level weights implied by the matching. In detail, let \(S(g)\) be the number of units indicated by target in group \(g\). Let \(T\) be the total number of units indicated by target in the sample. 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)}.$$

See matching_weights for more details.

covariate_averages focuses on means, but higher moments and interactions can be investigated by adding corresponding columns to the covariate matrix (see examples below).

Examples

Run this code
# 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"))

# Treatment group averages in unmatched sample
covariate_averages(my_data$treatment, my_data[c("x1", "x2")])

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

# Treatment group averages in matched sample
covariate_averages(my_data$treatment, my_data[c("x1", "x2")], my_matching)

# Averages in matched sample for ATT
covariate_averages(my_data$treatment,
                   my_data[c("x1", "x2")],
                   my_matching,
                   target = c("T1", "T2"))

# Second-order moments and interactions
mod_covs <- data.frame(x1 = my_data$x1,
                       x2 = my_data$x2,
                       x1sq = my_data$x1^2,
                       x2sq = my_data$x2^2,
                       x1x2 = my_data$x1 * my_data$x2)
covariate_averages(my_data$treatment, mod_covs, my_matching)

Run the code above in your browser using DataLab