Created
July 12, 2016 18:44
-
-
Save jmclawson/2037d0b548338071b928847757f483aa to your computer and use it in GitHub Desktop.
Convert SPSS data files to CSV and Stata using R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(foreign) | |
mytest.alldata <- list() | |
mytest.csvfile <- c() | |
mytest.dtafile <- c() | |
mytest.filelist <- list.files(path="data",pattern="*sav",recursive=FALSE,full.names=T) | |
for (number in 1:length(mytest.filelist)) { | |
mytest.alldata[[number]] <- read.spss(mytest.filelist[number],to.data.frame = TRUE) | |
mytest.csvfile[number] <- gsub("data/|.sav","",mytest.filelist[number]) | |
mytest.csvfile[number] <- paste(mytest.csvfile[number],".csv",sep="") | |
mytest.dtafile[number] <- gsub("csv","dta",mytest.csvfile[number]) | |
write.csv(mytest.alldata[[number]],mytest.csvfile[number]) | |
write.dta(mytest.alldata[[number]],mytest.dtafile[number]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment