In this post we look at how you would import a R dataset into Stata. In particular we will export the happy dataset which is in the productplots package. Doing it all from the beginning, on Windows would look something like this.
First, using chocolately install R and its dependencies.
choco install r.project -y
choco install rtools -y
choco install r.studio -y
When installations are complete, open R Studio and from the terminal install the productplots package.
install.packages("devtools")
devtools::install_github("hadley/productplots")
That’s it basically. In the console in R Studio, load up the happy dataset in order to verify that everythings working:
That’s all good. Now we are ready to export the dataset for use in Stata.
require(foreign)
write.dta(happy, "happy.dta")
Now the happy.dta dataset should be found on disk and ready to be used in Stata.