dimw | R Documentation |
Calculates the simple difference in means or weighted difference in means between the control or sample population and the treated or target population.
dimw(X, w, target)
X |
matrix of data where rows are observations and columns are covariates. |
w |
numeric vector of weights for each observation. |
target |
numeric vector of length equal to the total number of units where population/treated units take a value of 1 and sample/control units take a value of 0. |
dim |
the simple, unweighted difference in means. |
dimw |
the weighted difference in means. |
#let's say we want to get the unweighted DIM and the weighted DIM using weights from the kbal
#function with the lalonde data:
#load and clean data a bit
set.seed(123)
data("lalonde")
# Select a random subset of 500 rows
lalonde_sample <- sample(1:nrow(lalonde), 500, replace = FALSE)
lalonde <- lalonde[lalonde_sample, ]
xvars=c("age","black","educ","hisp","married","re74","re75","nodegr","u74","u75")
#get the kbal weights
kbalout= kbal(allx=lalonde[,xvars],
sampledinpop=FALSE,
treatment=lalonde$nsw)
#now use dimw to get the DIMs
dimw(X = lalonde[,xvars], w = kbalout$w, target = lalonde$nsw)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.