Introduction
This article describes how to import Stata DTA data sets into Displayr.
Requirements
- A Displayr document.
- A Stata (*.dta) data set made available as a URL. This example uses a 2017 face-to-face post-election survey data set.
Please note these steps require a Displayr license.
Method
1. Select Data Sources > Plus (+) > R.
2. Enter a name for the data set under Name.
3. Paste the below R code where it states "Enter your R code here":
library(haven)
# Import data
df = read_dta("http://www.britishelectionstudy.com/wp-content/uploads/2018/01/bes_f2f_2017_v1.2.dta")
# Convert as labels
df = as_factor(df)
Here, we read in the data set using haven's read_dta function. Next, we convert the data set so that it displays the labels rather than the values.
4. Note this will import using the variable names. Variable labels will need to be updated directly in your Data Sources tree.
See Also
How to Import Data into Displayr