match_weight: matching weights

View source: R/match_weight.R

match_weightR Documentation

matching weights

Description

Different weightings and some additional details I find useful in connection with a fullmatch (or similar matching)

Usage

match_weight(tr, cl, id, data = NULL, trv = 1)

Arguments

tr

the binary treatment variable, as character

cl

the clustering variable, as character

id

the id variable, as character.

data

the data

trv

the value of the treatment (of variable tr), '1' by default

Value

data frame with new parameters n, number of individuals in each cluster, tr_n the number of treated within the cluster, ctrl_n the number of controls within the cluster, ate.weight the weight for calculating the average treatment effect, att.weight the weight for calculating the average treatment effect for the treated, atc.weight the weight for calculating the average treatment effect for the controls, cid for describing the match it is useful to have a 'cluster id', use this with e.g. dplyr::group_by(tr, cid) and summarise with functions using weight = cl.weight to get stats for weighted treated and control statistics.

Examples

df <- data.frame(
   id = 1:13,
   foo = c(0,0,1, 0,1, 1,1,0, 1,1,0,0, 0),
   bar = c(rep(c(letters[1:4]), c(3,2,3,4)), NA),
   x = round(runif(13),2)
)
str(match_weight(data = df, tr = "foo", cl = "bar", id = "id"))
df$foo <- ifelse(df$foo == 1, "Treated", "Control")
str(match_weight(tr = df$foo, cl = df$bar, id = df$id, trv = "Treated"))

renlund/datma documentation built on June 2, 2025, 5:12 a.m.