In the absence of the desired feature, here’s an R work-around. The code below offers a simple template for the task of transforming variables with value labels into string variables whose values are the labels. The code only requires 2 inputs: the path to where the file is located (
dataPath), which needs to be specified slashes instead of backslashes; and the file name (
dataFile). The code could be extended to loop over all Stata files in a folder.
# load necessary libraries
# if you don't have them, do a one-time install via install.packages()
library(haven) # for reading Stata files into memory and preserving labels in labelled class
library(dplyr) # for data wrangling and identifying columns to be converted to character
library(stringr) # for changing the file extension from ".dta" to ".tab"
# read in data
dataPath = "C:/my/file/path/"
dataFile = "someData.dta"
myLabelledData <- read_stata(file = paste0(dataPath, dataFile), encoding = "UTF-8")
# create function to transform labelled variables to character variables
# first, transform labelled to factors, where levels are labels
# then, transform factor levels to characters
makeCharacter = function(x) x = as.character(as_factor(x, levels = "default"))
# apply function to all variables that have value labels
myCharacterData <- myLabelledData %>%
.predicate = is.labelled, # check whether var has Stata value labels
.funs = makeCharacter) # if so, transform var to string
# write to tab-delimited format
outputFile = str_replace(dataFile, "dta", "tab")
file = paste0(dataPath, outputFile),
sep = "\t",
row.names = FALSE,
fileEncoding = "UTF-8")