Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Code for converting CCD SAS files from NCES to Stata. Code should be followed by ConvertCCDtoStata_School.do, which does the final formatting for the data sets.
## ConvertCCDtoStata_School.R
## Richard Blissett (rsl.bliss@gmail.com)
# Environment settings
rm(list=ls())
library(haven)
# Basic information
setwd("~/Documents/CCD Data/School")
# For each year before 2008
ccdSchool.SAStoStata3 <- function(file1, file2, file3, year, loc="RawFiles/") {
# Read files
d1 <- read_sas(paste0(loc, file1))
d2 <- read_sas(paste0(loc, file2))
d3 <- read_sas(paste0(loc, file3))
# Append together
d <- rbind(d1, d2, d3)
# Write file
outname_dta <- paste0("ROutput/ccdSch_", year, ".dta")
write_dta(d, outname_dta)
}
# Run files
ccdSchool.SAStoStata3("sc001aai.sas7bdat", "sc001akn.sas7bdat", "sc001aow.sas7bdat", 2001)
ccdSchool.SAStoStata3("sc011aai.sas7bdat", "sc011akn.sas7bdat", "sc011aow.sas7bdat", 2002)
ccdSchool.SAStoStata3("sc021aai.sas7bdat", "sc021akn.sas7bdat", "sc021aow.sas7bdat", 2003)
ccdSchool.SAStoStata3("sc031aai.sas7bdat", "sc031akn.sas7bdat", "sc031aow.sas7bdat", 2004)
ccdSchool.SAStoStata3("sc041bai.sas7bdat", "sc041bkn.sas7bdat", "sc041bow.sas7bdat", 2005)
ccdSchool.SAStoStata3("sc051aai.sas7bdat", "sc051akn.sas7bdat", "sc051aow.sas7bdat", 2006)
ccdSchool.SAStoStata3("sc061cai.sas7bdat", "sc061ckn.sas7bdat", "sc061cow.sas7bdat", 2007)
# Conversion function
ccdSchool.SAStoStata1 <- function(file, year) {
# Read file
d <- read_sas(file)
# Write file
outname_dta <- paste0("ROutput/ccdSch_", year, ".dta")
write_dta(d, outname_dta)
}
# Run files
ccdSchool.SAStoStata1("RawFiles/sc071b.sas7bdat", 2008)
ccdSchool.SAStoStata1("RawFiles/sc081b.sas7bdat", 2009)
ccdSchool.SAStoStata1("RawFiles/sc092a.sas7bdat", 2010)
ccdSchool.SAStoStata1("RawFiles/sc102a.sas7bdat", 2011)
ccdSchool.SAStoStata1("RawFiles/sc111a_supp.sas7bdat", 2012)
ccdSchool.SAStoStata1("RawFiles/sc122a.sas7bdat", 2013)
ccdSchool.SAStoStata1("RawFiles/sc132a.sas7bdat", 2014)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment