如何使用 RStudio 使用 Stata 命令编写 RMarkdown 文件?

How to use RStudio to write a RMarkdown file with Stata commands?

我的问题在标题中说明了。我尝试编译示例 .Rmd 我在这里找到:http://www.ssc.wisc.edu/~hemken/Stataworkshops/Stata%20and%20R%20Markdown/ 除了在网上查找各种资源无济于事。虽然我的资源 Doug 能够编译 RMarkdown,但我收到以下 MWE 的错误。

MWE 是:

---
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/Stata.app"
opts_chunk$set(engine="stata", engine.path=statapath, comment="")
```

### Descriptive Statistics
A simple example.
```{r}
sysuse auto
summarize
```

来自 RStudio 控制台的 output/error 是:

processing file: stata.Rmd
  |................                                                 |  25%
   ordinary text without R code

  |................................                                 |  50%
label: unnamed-chunk-1 (with options) 
List of 2
$ echo   : logi FALSE
    $ message: logi FALSE

Loading required package: knitr
  |.................................................                |  75%
  ordinary text without R code

  |.................................................................| 100%
label: unnamed-chunk-2

running: /Applications/Stata/Stata.app  -q -b stata47b9d14e1c.do
Quitting from lines 20-22 (stata.Rmd) 
Error in engine(options) : 
  sh: /Applications/Stata/Stata.app: is a directory
Calls: <Anonymous> ... process_group.block -> call_block -> block_exec ->     in_dir -> engine
In addition: Warning message:
running command ''/Applications/Stata/Stata.app'  -q -b stata47b9d14e1c.do 2>&1' had status 126 
Execution halted

您 link 指向的页面指向 this page。那里写着:"For example, if Stata is installed in /Applications/Stata/, then the path to the Stata executable is /Applications/Stata/Stata.app/Contents/MacOS/",他们为所有不同风格的 Stata 提供了适当的 link。此外,您需要引用可执行文件,而不是它所在的文件夹。如果我如下更改您的 MWE,一切都对我有用(请注意,我使用 Stata-SE;您可能需要为您的系统更改它)。

---
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
```