【问题标题】:Is there any way to cross-reference fixest::etable()?有没有办法交叉引用 fixst::etable()?
【发布时间】:2021-12-24 22:51:10
【问题描述】:

问题

有没有办法交叉引用fixest::etable()? 我知道etable 是一个简单的方法,但它实际上非常有用。 如果有办法做到这一点,那将非常有帮助。

环境是 Windows 10,使用 R 4.1.2 并在 RStudio 中运行 bookdown::render_book()。 以下是文件结构和每个文件的内容。

  • index.Rmd
  • _bookdown.yml
  • _output.yml

源代码

index.Rmd

---
title: "test"
author: "null"
output: pdf_document
fontfamily: lmodern
documentclass: bxjsarticle
classoption: |
  xelatex,
  ja=standard,
  a4
link-citations: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
    echo = FALSE,
    warning = FALSE,
    message = FALSE,
    dev = "cairo_pdf",
    results = "asis"
)
```

```{r model}
library(fixest)
model <- feols(dist ~ speed, cars)
```

```{r etable}
etable(model, title = "etable", tex = TRUE)
```

\@ref(tab:etable)

_bookdown.yml

delete_merged_file: true

_output.yml

bookdown::pdf_document2:
    latex_engine: xelatex
    dev: cairo_pdf
    fig_caption: yes
    number_sections: true

结果

如图所示,交叉引用为“??”。 现在,我必须手动给它们编号,而不使用交叉引用。

【问题讨论】:

    标签: r bookdown cross-reference fixest


    【解决方案1】:

    更新:我不知道为什么我错过了label 参数。无论如何,@laurent-bergé 更正确。

    注意:此答案翻译自my original post(日文)。

    我猜 fixest 包在 Rmd 上没有交叉引用选项。虽然它可能是一种杂物,但我发现您可以在 title 参数中插入 LaTeX 命令,如下所示。

    ```{r etable}
    etable(model, title = "\\label{tab:etable}etable", tex = TRUE)
    ```
    

    附录:一般而言,bookdown 不支持通过块标签引用表格,仅支持绘图。其他包(例如officedown)可以通过块标签引用表格。

    您也可以使用 stargazer pacakge 轻松将回归分析的结果制成表格,但您可能还需要一些技巧(请参阅https://github.com/rstudio/bookdown/issues/175)。

    【讨论】:

      【解决方案2】:

      etable 有一个 label 参数:

      library(fixest)
      model = feols(dist ~ speed, cars)
      etable(model, label = "tab:etable", tex = TRUE)
      
      #> \begin{table}[htbp]
      #>    \caption{\label{tab:etable} no title}
      #>    \centering
      #>    \begin{tabular}{lc}
      #>       \tabularnewline \midrule \midrule
      #>       Dependent Variable: & dist\\  
      #>       Model:              & (1)\\  
      #>       \midrule
      #>       \emph{Variables}\\
      #>       (Intercept)         & -17.58$^{**}$\\   
      #>                           & (6.758)\\   
      #>       speed               & 3.932$^{***}$\\   
      #>                           & (0.4155)\\   
      #>       \midrule
      #>       \emph{Fit statistics}\\
      #>       Observations        & 50\\  
      #>       R$^2$               & 0.65108\\  
      #>       Adjusted R$^2$      & 0.64381\\  
      #>       \midrule \midrule
      #>       \multicolumn{2}{l}{\emph{IID standard-errors in parentheses}}\\
      #>       \multicolumn{2}{l}{\emph{Signif. Codes: ***: 0.01, **: 0.05, *: 0.1}}\\
      #>    \end{tabular}
      #> \end{table}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-29
        • 1970-01-01
        • 2017-03-14
        • 2017-06-20
        • 2020-03-23
        • 1970-01-01
        相关资源
        最近更新 更多