Skip to content

Instantly share code, notes, and snippets.

@jepusto
Created November 26, 2024 15:54
Show Gist options
  • Save jepusto/9cdb430e415996d1fcb19b362bd71183 to your computer and use it in GitHub Desktop.
Save jepusto/9cdb430e415996d1fcb19b362bd71183 to your computer and use it in GitHub Desktop.
An example of inverse propensity weighting and weighted least squares regression adjustment for estimating an average treatment effect among treated units, using the entropy-balancing propensity score
library(cobalt)
library(WeightIt)
library(marginaleffects)
data("lalonde")
lalonde_trt <- subset(lalonde, treat == 1)
# ATT weighting with entropy-balancing
w_ebal <- weightit(
treat ~ age + educ + race + married + nodegree + re74 + re75,
data = lalonde,
method = "ebal",
estimand = "ATT"
)
IPW_fix <-
lm_weightit(
re78 ~ treat,
data = lalonde,
weightit = w_ebal,
vcov = "HC0"
) |>
avg_comparisons(variables = "treat", newdata = lalonde_trt)
IPW_inf <-
lm_weightit(
re78 ~ treat,
data = lalonde,
weightit = w_ebal
) |>
avg_comparisons(variables = "treat", newdata = lalonde_trt)
IPW_inf
WLS_fix <-
lm_weightit(
re78 ~ treat * (age + educ + race + married + nodegree + re74 + re75),
data = lalonde,
weightit = w_ebal,
vcov = "HC0"
) |>
avg_comparisons(variables = "treat", newdata = lalonde_trt)
WLS_fix
WLS_inf <-
lm_weightit(
re78 ~ treat * (age + educ + race + married + nodegree + re74 + re75),
data = lalonde,
weightit = w_ebal
) |>
avg_comparisons(variables = "treat", newdata = lalonde_trt)
WLS_inf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment