Importing ASCII format data from the American National Election Study¶
The following makes use of the memisc package. You may need to install it
from CRAN using the code
install.packages("memisc") if you want to run this on your computer. (The package is already installed on
the notebook container, however.)
Loading required package: lattice Loading required package: MASS Attaching package: 'memisc' The following objects are masked from 'package:stats': contr.sum, contr.treatment, contrasts The following object is masked from 'package:base': as.array
This data file is available from the American National Election Study website, along with syntax files in which the structure of the data is declared, as well as the variable lables (descriptions), value labels, and missing values. In order to obtain these data files (and run the notebook successufully), you need to download them from the ANES website for 2008 and upload them to the virtual machine that runs this notebook. To do this,
- pull down the “File” menu item and select “Open”
- An overview of the folder that contains the notebook opens.
- The folder view has a button labelled “Upload”. Use this to upload the file that you downloaded from the ANES website.
Note that the uploaded data will disappear, once you “Quit” the notebook (and the Jupyter instance).
# Note that the following code takes quite a while ... anes2008TS <- spss.fixed.file( "anes2008TS_dat.txt", columns.file = "anes2008TS_col.sps", varlab.file = "anes2008TS_lab.sps", codes.file = "anes2008TS_cod.sps", missval.file = "anes2008TS_md.sps")
V080001 'ID.1. CASE ID' V080101 'WT.1. PRE CROSS-SECTION SAMPLE WEIGHT - POST-STRAT, centered' V080101a 'WT.1. PRE CROSS-SECTION SAMPLE WEIGHT - POST-STRATIFIED' V080102 'WT.2. POST CROSS-SECTION SAMPLE WEIGHT -POST-STRAT, centered' V080102a 'WT.2a. POST CROSS-SECTION SAMPLE WEIGHT -POST-STRATIFIED' V080103 'WT.3. HOUSEHOLD WEIGHT: Household post-stratified' V081001 'STUDY.1. Waves completed by respondent' V081101 'HHList.1. Respondent: gender' V081102 'HHList.2. Respondent: race' V081103 'HHList.3. Respondent: Latino status' V081103a 'HHList.3a. Respondent: race and Latino status' V081104 'HHList.4. Respondent: age' V081105 'HHList.5. RESTRICTED: Respondent: relationship to informant' V081106 'HHList.6. Respondent: eligible adult number' V081107 'HHList.7. TOTAL IN HH: PERSONS (ADULTS AND CHILDREN)' V081108 'HHList.8. TOTAL IN HH: ADULTS (18 BY OCT30)' V081108a 'HHList.8a. TOTAL IN HH: ELIGIBLE ADULTS' V081108b 'HHList.8b. TOTAL IN HH:INELIGIBLE ADULTS (18 BY OCT30)' V081108c 'HHList.8c. TOTAL IN HH: FEMALE ELIGIBLE ADULTS (18 BY OCT30)' V081108d 'HHList.8d. TOTAL IN HH: MALE ELIGIBLE ADULTS (18 BY OCT30)' V081108e 'HHList.8e. TOTAL IN HH: LATINO ELIGIBLE ADULTS (18 BY OCT30)' V081108f 'HHList.8f. TOTAL IN HH: BLACK ELIGIBLE ADULTS (18 BY OCT30)' V081108g 'HHList.8g. TOTAL IN HH: WHITE ELIGIBLE ADULTS (18 BY OCT30)' V081108h 'HHList.8h. TOTAL IN HH: MIXED/OTH RACE ELIG ADULTS' V081109 'HHList.9. TOTAL IN HH: CHILDREN UNDER 18 (NOT 18 BY OCT30)' V081109a 'HHList.9a. TOTAL IN HH: CHILDREN UNDER 17' V081109b 'HHList.9b. TOTAL IN HH: CHLDREN 17 YRS OLD, NOT 18 BY OCT30' V081110 'HHList.10. HOUSEHOLD COMPOSITION' V081111a 'HHList.11a. ELIGIBLE PERSON #1: gender' V081111b 'HHList.11b. ELIGIBLE PERSON #1: race'