public
Last active

foreignR

  • Download Gist
foreign.r
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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")

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.