Simulating second difference using Zelig
[This article was first published on Shige's Research Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I am trying to simulate second difference using Zelig, here is my code:Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
——————————————————–
data(turnout)
# estimation
z.out <- zelig(vote ~ race*age + educate + income,
model = “logit”, data = turnout)
summary(z.out)
# first difference
x.low <- setx(z.out, educate = 12)
x.high <- setx(z.out, educate = 16)
s.out <- sim(z.out, x = x.low, x1 = x.high)
s.low <- sim(z.out, x=x.low)
s.high <- sim(z.out, x=x.high)
dif <- (s.high$qi$ev - s.low$qi$ev)
# second difference
x.low.low <- setx(z.out, educate = 12, age = 20)
x.low.high <- setx(z.out, educate = 12, age = 30)
x.high.low <- setx(z.out, educate = 16, age = 20)
x.high.high <- setx(z.out, educate = 16, age = 30)
s1 <- sim(z.out, x = x.low.low, x1 = x.low.high)
s2 <- sim(z.out, x = x.high.low, x1 = x.high.high)
did1 <- s1$qi$fd - s2$qi$fd
# or equivalent
s3 <- sim(z.out, x = x.low.low, x1 = x.high.low)
s4 <- sim(z.out, x = x.low.high, x1 = x.high.high)
did2 <- s3$qi$fd - s4$qi$fd
———————————————————
It would be great if Zelig can do this directly though.
To leave a comment for the author, please follow the link and comment on their blog: Shige's Research Blog.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.