[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:
——————————————————–

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.