Skip to content!

R_en

With the help of a small script (TXT, 1.88 KB)(Linux/bash) you can easily convert stata files to R datafiles.

However R is capable to read stata files directly as well as other formats with the package "foreign" installed.
For further information see the R-manual.

With the following code you may import the variable names and value labels from stata to the R datafiles (example for the bdp file):

 ##### ----- R Example #####
require(foreign)
bdp <- read.dta("bdp.dta")

head(data.frame(varnames=names(bdp), varlabels=attributes(bdp)$var.labels))

var.info <- vector(length=ncol(bdp), mode="list")
names(var.info) <- names(bdp)
for(i in seq(along.with = var.info)) {
     var.info[[i]]$varlab <- attributes(bdp)$var.labels[i]
     var.info[[i]]$vallab <- (attributes(bdp)$label.table[attributes(bdp)$val.labels])[[i]]
}

var.info["bdp0101"]

##### ----- R Example #####


keyboard_arrow_up