Closed waynelapierre closed 1 year ago
A function like that would do one thing, which would be to append the weights to the dataset, but you can do that yourself, e.g., lalonde$weights <- eb_data$weights
. In MatchIt
, match.data()
does more; it discards unmatched units and assigns matched strata, and does so in a way such that outputs from multiple matchit()
calls on different portions of the dataset can be automatically combined. But none of that is necessary with WeightIt
. Just assign the weights to a variable in the original dataset and you can reorder or subset that data as you like.
You don't need to sort your data in anyway to use weightit()
or matchit()
; that just happens to be how the lalonde
dataset is structured.
OK. It seems that the order of the data is reflected in the output of weightit, which is good.
require(data.table)
require(WeightIt)
data(lalonde)
setDT(lalonde)
eb_data <- weightit(treat ~ age + educ + race + married + nodegree + re74 + re75,
data = lalonde, method = "ebal", estimand = "ATT")
eb_model <- lm(re78 ~ treat + age + educ + race + married + nodegree + re74 + re75,
data = lalonde, weights = eb_data$weights)
summary(eb_model)
setorder(lalonde, age, educ)
eb_data <- weightit(treat ~ age + educ + race + married + nodegree + re74 + re75,
data = lalonde, method = "ebal", estimand = "ATT")
eb_model <- lm(re78 ~ treat + age + educ + race + married + nodegree + re74 + re75,
data = lalonde, weights = eb_data$weights)
summary(eb_model)
Could you add to this package a weight.data function that is similar to match.data of MatchIt?
Since eb_data$weights is not a column of lalonde, I am not sure if lalonde can be sorted in a different order or its treatment column needs to be 1, 1, ..., 0, 0, ... When using a different dataset, do I need to sort the data by its treatment column in descending order before using it with weightit?