Skip to content

Instantly share code, notes, and snippets.

@cdesante
Created December 3, 2012 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdesante/4197647 to your computer and use it in GitHub Desktop.
Save cdesante/4197647 to your computer and use it in GitHub Desktop.
foreignR
doInstall <- TRUE
toInstall <- c("foreign")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
#http://cran.r-project.org/web/packages/foreign/foreign.pdf
#setwd("your working directory here")
library(foreign)
STATA <- read.dta("stata.dta")
head(STATA)
table(STATA$region)
STATA <- read.dta("stata.dta", convert.factors=FALSE)
head(STATA)
STATA <- read.dta("stata.dta", convert.factors=FALSE, convert.underscore=TRUE)
head(STATA)
table(STATA$region)
write.dta(STATA, "fromR.dta")
write.dta(STATA, "fromRfactors.dta", convert.factors="labels")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment