Raking 2016 American National Election Study data

The following makes use of the survey package. You may need to install it from CRAN using the code install.packages("survey") if you want to run this on your computer. (The package is already installed on the notebook container, however.)

library(survey)
Loading required package: grid
Loading required package: Matrix
Loading required package: survival

Attaching package: 'survey'

The following object is masked from 'package:graphics':

    dotchart

Here we rake the sample design object by recalled vote in 2012 and vote in 2016

load("anes-2016-vprevote-design.RData")
load("popl-results.RData")
anes_2016_prevote_desgn_rake <- rake(
    anes_2016_vprevote_desgn,list(~recall12,~vote16),
    population=list(pop.recall12,pop.vote16),
    control=list(maxit=20))

Of course, the marginal distributions of the vote in 2012 and the vote in 2016 are no longer estimated, so that standard errors now vanish.

100*svymean(~recall12,design=anes_2016_prevote_desgn_rake)
                    mean SE
recall12Obama   28.01970  0
recall12Romney  25.90182  0
recall12Other    0.95053  0
recall12No vote 45.12795  0
100*svymean(~vote16,design=anes_2016_prevote_desgn_rake)
                 mean SE
vote16Clinton 26.3355  0
vote16Trump   25.1883  0
vote16Other    3.1324  0
vote16No vote 45.3439  0

The actual percentage of non-voters in 2016 is obviously much higher than the one estimated from the sample, be it post-stratified or not.

We save the raked data for later use.

save(anes_2016_prevote_desgn_rake,file="anes-2016-prevote-desgn-rake.RData")