** Open up R interactively through Stata ** Enda Patrick Hargaden ** Boyd Center / Economics ** University of Tennessee, July 2016 ** For sample purposes, let's use the auto dataset. Obviously you change this to your data. clear sysuse auto ** Get R ready saveold holderfile.dta, ver(12) replace global Rterm_path `"C:/Program Files/R/R-3.3.0/bin/x64/Rterm.exe"' local r_pwd = subinstr("`c(pwd)'","\","/",.) rsource, terminator("end_r_stata") roptions(`" --vanilla --args "`r_pwd'" "') stata_pwd = commandArgs(trailingOnly=TRUE); setwd(stata_pwd[1]); library("foreign"); library("ggplot2"); df <- read.dta("holderfile.dta", convert.f=TRUE); file.remove("holderfile.dta"); ggplot(df, aes(x=mpg, y=price, color=foreign)) + geom_point() + ggtitle("Ahh, lovely R graphs through Stata") ggsave("ggplot_stata.pdf") end_r_stata