MYaseen208
MYaseen208

Reputation: 23898

How to use RStudio to write R Markdown files with Stata graphs?

The code below works for Stata commands and output but does not produce the graphs:

---
title: "Stata and R Markdown (Windows)"
author: "Doug Hemken"
date: "July 2015"
output: 
html_document:
toc: yes
---

```{r, echo=FALSE, message=FALSE}
require(knitr)
statapath <- "/Applications/Stata/StataSE.app/Contents/MacOS/stata-se"
opts_chunk$set(engine="stata", engine.path=statapath, comment="")
```

### Descriptive Statistics
A simple example.

```{r}
sysuse auto
summarize
```

```{r}
sysuse auto
twoway (scatter mpg weight)
```

Note that this is a follow-up of this question:

Upvotes: 0

Views: 487

Answers (1)

user8682794
user8682794

Reputation:

You need to export the graph and include an image link in the R Markdown as follows:

```{stata, echo=1, results="hide"}
twoway (scatter mpg weight)
graph export "myscatter.svg", replace
```

Upvotes: 1

Related Questions