The goal of this assignment is to replicate the tables created within the report title “Analysing the American National Election Study using the memisc package,” by Martin Elff
The first step was to import the data into R
library(DescTools)
library(memisc)
library(foreign)
options(digits=3)
nes1948.por <- UnZip("anes/NES1948.ZIP","NES1948.POR",package="memisc")
nes1948 <- spss.portable.file(nes1948.por)
names (nes1948)
## [1] "vversion" "vdsetno" "v480001" "v480002" "v480003" "v480004"
## [7] "v480005" "v480006" "v480007" "v480008" "v480009" "v480010"
## [13] "v480011" "v480012" "v480013" "v480014a" "v480014b" "v480015a"
## [19] "v480015b" "v480016a" "v480016b" "v480017a" "v480017b" "v480018"
## [25] "v480019" "v480020" "v480021a" "v480021b" "v480022a" "v480022b"
## [31] "v480023" "v480024" "v480025a" "v480025b" "v480026" "v480027"
## [37] "v480028" "v480029" "v480030" "v480031a" "v480031b" "v480031c"
## [43] "v480032a" "v480032b" "v480032c" "v480033a" "v480033b" "v480034a"
## [49] "v480034b" "v480035a" "v480035b" "v480036a" "v480036b" "v480037"
## [55] "v480038" "v480039" "v480040" "v480041" "v480042" "v480043"
## [61] "v480044" "v480045" "v480046" "v480047" "v480048" "v480049"
## [67] "v480050"
Next, a subset was created:
vote.48 <- subset(nes1948,select=c(v480018, v480029, v480030, v480045, v480046, v480047, v480048, v480049, v480050))
This subset contained several variables. For the purpose of this excercise, I focused on 3 of them, which were recoded using the reshape package.
library(Rcpp)
library(reshape)
vote.48 <- rename(vote.48, c(v480018 = "VotedChoice"))
vote.48 <- rename(vote.48, c(v480046 = "Race"))
vote.48 <- rename(vote.48, c(v480050 = "ReligiousPref"))
Within the variables, some columns and rows were combined. For the religions, I combined the categories “Jewish” and “Others” to match the tables
library(car)
vote.48$votedChoice3 <-recode(vote.48$VotedChoice, "'VOTED - FOR TRUMAN'='Truman';'VOTED - FOR DEWEY'='Dewey';'VOTED - FOR WALLACE'='Other'; 'VOTED - FOR OTHER'='Other';else=NA")
vote.48$Race2 [vote.48$Race == "WHITE"] = "White"
vote.48$Race2 [vote.48$Race == "NEGRO"] = "Black"
vote.48$religiousPref2 <- recode(vote.48$ReligiousPref, "'PROTESTANT'='Protestant';'CATHOLIC'='Catholic';'JEWISH'='Other, none'; 'OTHER'='Other, none'; 'NONE'='Other, none' ;else=NA")
Next, these 2 varibales were compared using the stargazer, tidyr, and plyr packages