So this is the code chunk I am trying to put in a custom function
treated.median <- with(subset(dta, catholic == 1), Hmisc::wtd.quantile(score, probs = .5))
counterfactual <- with(subset(dta, catholic == 0), Hmisc::wtd.quantile(score, ipw_tot, probs = .5))
QTET <- treated.median - counterfactual
QTET
the output this gives me when running it is
50%
-1.083
I tried to make it a function like this
ZIB <- function(data, k, s, t) {
treated.median <- with(data[k == 1,], Hmisc::wtd.quantile(s, probs = .5))
counterfactual <- with(data[k == 0,], Hmisc::wtd.quantile(s, t, probs = .5))
QTET <- treated.median - counterfactual
return(QTET)
}
ZIB(dta,
dta$catholic, dta$score, dta$ipw_tot)
the output I get is this
50%
-2.397
What am I missing here? Why am I getting two different answers? (I have a feeling that it might be a very silly thing that I am missing).