Meijing,
The issue in the code you sent along seems to stem from passing the
formula to your function, not so much MatchIt. See the code below.
Dan
------------
rm(list=ls())
library(MatchIt)
library(Zelig)
library(twang)
data(lalonde)
m.out1 <- matchit(treat ~ age + educ + black + hispan + nodegree +
married + re74 + re75, method = "nearest", data = lalonde)
match.a <- match.data(m.out1)
match.c <- match.data(m.out1, "control")
match.t <- match.data(m.out1, "treat")
PM.ATT <- function()
{ # Average treatment effect on the treated (ATT)
# We do this by estimating the coeffcients
# in the control group alone
z.out1 <- zelig(formula=form, data = match.c, model = "ls")
x.out1 <- setx(z.out1, data = match.t,cond = TRUE)
s.out1 <- sim(z.out1, x = x.out1)
ATT <- summary(s.out1)
return(ATT)
}
form <- formula(re78 ~ age + educ + black + hispan + nodegree +
married + re74 + re75)
PM.ATT()
On Mon, Jun 25, 2012 at 6:07 PM, Meijing WU <wenny2700(a)hotmail.com> wrote:
Hi Dear Dr. Imai,
I am trying to write a R function of ATT caclulation with Zelig for post
matching analysis after using matchit for matching in propensity score
analysis.
ATT caclulation didn't work out when I put them into the function, and I
couldn' find out what's wrong with it.
Would you please help me out with this problem? I really appreciate that.
The following is my code.
###########################
library(twang)
data(lalonde)
m.out1 <- matchit(treat ~ age + educ + black + hispan + nodegree + married +
re74 + re75, method = "nearest", data = lalonde)
match.a=match.data(m.out1)
match.c=match.data(m.out1, "control")
match.t=match.data(m.out1, "treat")
PM.ATT <-
function(formula)
{ # Average treatment effect on the treated (ATT)
# We do this by estimating the coeffcients
# in the control group alone
z.out1 <- zelig(formula, data = match.c , model = "ls")
x.out1 <- setx(z.out1, data = match.t,cond = TRUE)
s.out1 <- sim(z.out1, x = x.out1)
ATT <- summary(s.out1)
return(ATT)
}
PM.ATT(re78 ~ age + educ + black + hispan + nodegree + married + re74 +
re75)
#######################################
Thanks and best regards,
Meijing WU
PHD student
Dept. of health statistics
second military medical university
shanghai, china
-
---
MatchIt mailing list served by HUIT
List Address: matchit(a)lists.gking.harvard.edu
Subscribe/Unsubscribe:
http://lists.gking.harvard.edu/mailman/listinfo/ei
MatchIt Software and Documentation:
http://gking.harvard.edu/matchit/
Browse/Search List Archive:
http://lists.gking.harvard.edu/mailman/private/matchit/
Matchit mailing list
Matchit(a)lists.gking.harvard.edu
https://lists.gking.harvard.edu/mailman/listinfo/matchit