library(memisc)
## The following code works with example data from the 2017 German Longitudinal
## Election study: It code combines pre- and post-election variables in the to a single
## party-preference variable for the first (candidate) vote and the second (list) vote
gles2017.sav <- spss.system.file("ZA6802_en_v3-0-1.sav")
description(gles2017.sav)
gles2017.vote <- subset(gles2017.sav,
select=c(
survey = survey1,
pre.turnout.int = v10,
post.turnout = n10,
pre.voteint.first = v11ab,
pre.voteint.second = v11bb,
post.vote.first = n11ab,
post.vote.second = n11bb,
pre.postvote.first = v12ab,
pre.postvote.second = v12bb
))
codebook(gles2017.vote)
gles2017.vote <- within(gles2017.vote,{
vote.first <- cases(
survey == 0 & pre.turnout.int == 6 -> pre.postvote.first,
survey == 0 & pre.turnout.int %in% 4:5 -> -85,
survey == 0 & pre.turnout.int %in% 1:3 -> pre.voteint.first,
survey == 1 & post.turnout ==1 -> post.vote.first,
survey == 1 & post.turnout ==2 -> -85,
TRUE -> -97
)
vote.second <- cases(
survey == 0 & pre.turnout.int == 6 -> pre.postvote.second,
survey == 0 & pre.turnout.int %in% 4:5 -> -85,
survey == 0 & pre.turnout.int %in% 1:3 -> pre.voteint.second,
survey == 1 & post.turnout ==1 -> post.vote.second,
survey == 1 & post.turnout ==2 -> -85,
TRUE -> -97
)
vote.first <- as.item(vote.first, labels = labels(pre.postvote.first))
vote.second <- as.item(vote.second, labels = labels(pre.postvote.second))
valid.range(vote.first) <- valid.range(vote.second) <- c(1,900)
})
codebook(gles2017.vote[c("vote.first","vote.second")])
Social Science Surveys¶
This chapter introduces the extension package memisc, which is specifically designed to address several of the challenges that were discussed in the previous chapter. It shows how a the system memory can be saved by importing subsets of variables and observations; how variables can be renamed so that results are more easy to interpret; how certain metadata can be used, that are not provided for by a basic R installation, such as value labels and user-defined missing values. The chapter also provides examples for more complex recodings of variables, e.g. for the construction of Goldthorpe class categories for households from ISCO-coded occupations of survey respondents and the creation of codebooks.
Below is the supporting material for the various sections of the chapter.
Importing survey data¶
Importing data from the British Election Study in SPSS format¶
Interactive notebook:
Script file:
importing-BES-data.RRequired data file:
83BES.savwhich is available fromhttps://www.britishelectionstudy.com/data-object/1983-bes-cross-section/(Note that the file available from this link has filename extension.sav, but [last time I checked] is actually has an SPSS “portable” format, so that the filename extension.porwould have appeared more appropriate.)The script makes use of the memisc package, which is available from
https://cran.r-project.org/package=memiscImporting data from the American National Election Study in ASCII format with acompanying SPSS code¶
Interactive notebook:
Script file:
importing-BES-data.RRequired data files:
anes2008TS_dat.txt,anes2008TS_col.sps,anes2008TS_lab.sps,anes2008TS_cod.sps,anes2008TS_md.spswhich are available fromhttps://electionstudies.org/data-center/2008-time-series-study/(as ASCII variant of the data).The script makes use of the memisc package, which is available from
https://cran.r-project.org/package=memiscRecoding and other transformations¶
Recoding data from the British Election Study¶
Interactive notebook:
Script file:
recoding-BES.RRequired data file:
BES-1983-classvot.RData, which is created in the first example.The script makes use of the memisc package, which is available from
https://cran.r-project.org/package=memiscCombining variables using case distinctions¶
Interactive notebook:
Script file:
recoding-GLES.RRequired data file:
ZA6802_en_v3-0-1.sav, which is available fromhttps://doi.org/10.4232/1.13236The script makes use of the memisc package, which is available from
https://cran.r-project.org/package=memisc