【问题标题】:RMarkdown: Statamarkdown produces undesired output when collectcode=TRUERMarkdown:当 collectcode=TRUE 时,Statamarkdown 会产生不需要的输出
【发布时间】:2020-08-25 14:59:57
【问题描述】:

我正在使用Statamarkdown 使用RMarkdown 和Stata 生成HTML 文档。

正如 here 所记录的,每个代码块都作为单独的 Stata 会话执行。 collectcode=TRUE 是一个块选项,用于跨块收集 Stata 代码。

虽然这很好地工作,但在第一个带有collectcode=TRUE 的块之后的第二个(以及任何其他)块的输出在顶部包含一个不需要的回声:

正在运行.......\profile.do

例如,当使用{stata stata2, echo = T,collectcode=TRUE} 运行第二个块时

   reg mpg price i.foreign ,  noheader  

产生这个输出:

reg mpg price i.foreign ,  noheader  
Running C:\Cloud\Methods\prog\profile.do . reg mpg price i.foreign ,  noheader  
------------------------------------------------------------------------------
         mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       price |   -.000959   .0001815    -5.28   0.000     -.001321    -.000597
             |
     foreign |
    Foreign  |   5.245271   1.163592     4.51   0.000     2.925135    7.565407
       _cons |   25.65058   1.271581    20.17   0.000     23.11512    28.18605
------------------------------------------------------------------------------

这是我的 RMarkdown 代表:

---
title: "Statamarkdown output problem"
output: html_document
---

```{r setup, include = F}
library(Statamarkdown)
```


First chunk is clean:

```{stata stata1,collectcode=TRUE}
sysuse auto
su mpg price
```

Second Stata Output contains undesired `Running .......\profile.do` output:

```{stata stata2, echo = T,collectcode=TRUE}
reg mpg price i.foreign ,  noheader  
```

Problem persists even in chunks with `collectcode=FALSE`:

```{stata new_data, echo = T,collectcode=F}
webuse bpwide, clear
su sex agegrp
```

`cleanlog = F` does not do the trick:
```{stata new_data2, echo = T,collectcode=F, cleanlog = FALSE}
webuse bpwide, clear
su sex agegrp
```

完全避免collectcode=T,即为每个块加载和准备数据当然是一种解决方法,但非常乏味。

我在 Windows 机器上使用 R 3.6.3 和 Stata 16.1。

非常感谢任何想法!

【问题讨论】:

  • 谢谢!不幸的是,删除echo 不会改变有问题的输出避免collectcode 会破坏代码。我必须在同一个块中做sysuse autoreg mpg price i.foreign , noheader。这个例子不是问题。但是,通常在运行模型等之前需要做一些准备。这就是为什么在这里删除collectcode=T 不是一个选项
  • 我在所有块中都包含了echocollectcode。你的代码在我的机器上没有问题。
  • 非常感谢!我应该在我的问题中添加更多信息:我正在使用 Windows10、R 3.6.3 和 Stata16.1 - 您的设置是否有任何不同?
  • 我使用的是 Windows 10、R 4.02、Stata 14。Statamarkdown 0.4.5。我尝试了各种组合,但无法重现您的问题。我可能错过了一些东西。如果你还有问题,我明天再看看
  • 非常感谢!这似乎是 Stata16 的问题 - 切换到 Stata13 解决了有问题的输出,但在输出表中创建了换行符。现在我可以使用set linesize 200 解决这个问题。谢谢!

标签: r markdown stata


【解决方案1】:

原来Stata是从

running .......\profile.do

Running .......\profile.do

Statamarkdown 软件包的新版本 (0.5.0) 现在可以满足此要求。

【讨论】:

    猜你喜欢
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 2016-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    相关资源
    最近更新 更多