Simulating second difference using Zelig

February 11, 2011
By

(This article was first published on Shige's Research Blog, and kindly contributed to R-bloggers)

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. 

To leave a comment for the author, please follow the link and comment on his blog: Shige's Research Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.