STATA 13 NEW FEATURES CODE
Here’s some demo code to make a figure with ggstatsplot (which is very awesome and you should check it out). Let’s make a figure in ggstatsplot using Stata and Rcall Varying dot size by a third variable can be done in Stata using weighted markers, as FYI. Labs(title="ggplot2 demo", x="MPG", y="Weight", caption="Caption!") Geom_point(aes(col=foreign, size=headroom)) + /// rcall: e<- ggplot(data, aes(x=mpg, y=weight)) + /// Remember to end every non-final line with the three forward slashes.
You can swap out the “rcall: e <- ggplot(…)" bit above for the following. You can get much more complex with the figure, like specifying colors by foreign status, specifying dot size by headroom size, adding a loess curve with 95% CI, and adding some labels. Here’s what it made! It was saved in my Documents folder, but check the output above to see where you working directory is. Rcall: e<- ggplot(data, aes(x=mpg, y=weight)) + /// now make a scatterplot with ggplot2, note the three slashes for line break Rcall: head(data, n=10) // now look at the first 10 rows of the data in R Rcall: names(data) // prove that you can see the variables. Rcall: data<- st.data() // move auto dataset to r move Stata's auto dataset over to R and prove it's there. Rcall: library(ggplot2) // load the ggplot2 library Rcall clear // starts with a new instance of R set up rcall, clean session and load necessary packages If your ggplot command extends across multiple lines, make sure to end each line (except the final line) with the three forward slash (“///”) line break notation that is used by Stata. Check out the demo figures from this page as well. Here’s some demo code to make a figure with ggplot2, which is the standard for figures in R. Let’s make a figure in ggplot2 using Stata and Rcall For our purposes, we are going to focus on the interactive mode since this allows you to manipulate R from within a do file. There are four modes for using Rcall: vanilla, sync, interactive, and console. –rcall clear– reboots R as a new instance. In brief, you can send datasets from Stata to R using –rcall st.data()–. You should read details on the Rcall help file (type –help rcall– in Stata) for an overview. If all goes well, it should install! Using Rcall
STATA 13 NEW FEATURES INSTALL
Now install Rcall itself from the Stata command line: github install haghish/rcall, stable From the Stata command line, type: net install github, from("") You need to install a separate package to allow you to install things from Github in Stata. Rcall’s installation is within Stata (as usual for Stata programs) but originates from Github, not the usual SSC install. After these finish installing, you can close R. Just pick one geographically close to you. It’ll prompt you to set up an install directory and choose your mirror/repository. In R, type: install.packages("readstata13") I have also gotten an error saying “‘Rcpp_precious_remove’ not provided by package ‘Rcpp'”, which was fixed by installing Rcpp, so install that too. This includes dplyr, tidyr, readr, purrr, tibble, stringr, forcats, import, wrangle, program, and model. Tidyverse also installs several other packages useful in data science that you might need later. We are going to install Tidyverse instead of ggplot2 alone. Note: ggplot2 is included in the excellent multi-package collection called Tidyverse. While you’re at it, install ggplot2 and ggstatsplot. Open R and install the readstata13 package, which is required to install Rcall. I have no reason to think that this wouldn’t work with Stata 13 or newer.) Installation of R, R packages, and Rcall (you only need to do this once)ĭownload and install R. I came across the Rcall package that allows Stata to interface with R and use some of these advanced features. There’s some cutting edge functionality and graphical tools in R that are missing in Stata. Each section links to further details and examples to help users get the best out of their software.Īdditionally, to read about the new features specific to Stata 13, including treatment effects, multilevel GLM, power and sample size, generalised SEM, forecasting, effect sizes, long strings and BLOBs, Project Manager and much more, click here.Stata is great because of its intuitive syntax, reasonable learning curve, and dependable implementation. Find out all about Stata’s expansive range of statistical features using the table of contents below.