This discussion assumes you already have a basic understanding of Markdown for document formatting, Rmarkdown to include executable code in a document, and Stata to write the code.

First attach the Statamarkdown library

Your first code chunk will look something like this:

```r`r ''`
library(Statamarkdown)
```

This will either report that Stata was found, or that you need to specify it\'s location yourself.

library(Statamarkdown)

You can hide all of this so it does not appear in your final document by using the include=FALSE chunk options.

If Stata was not found

You will need to specify this yourself, as additional lines in the \"library\" code block above.

stataexe <- "C:/Program Files/Stata18/StataSE-64.exe" # Windows
# stataexe <- "/Applications/Stata/StataSE.app/Contents/MacOS/StataSE" # Mac OS
# stataexe <- "/usr/local/stata18/stata-se" # Unix
knitr::opts_chunk$set(engine.path = list(stata = stataexe))

If you do not know where to find you Stata executable (app), open Stata and issue the command sysdir. The line labeled STATA: is the folder where your Stata executable is located. You can browse there with your computer\'s file explorer to see the actual file name of the Stata executable, which varies by operating system, Stata version, and Stata flavor.

Then make the Stata executable path a default chunk option.

Then set up Stata code chunks.

A simple code chunk in Rmarkdown might look like:

```{stata example}`r ''`
sysuse auto
summarize
```

And in your document this would produce: {stata example} sysuse auto summarize



Hemken/Statamarkdown documentation built on Dec. 11, 2023, 3:59 a.m.