Is there any way to cross-reference fixest::etable()?

Solution 1:

UPDATE: I have no idea why I missed the label argument. Anyway, @laurent-bergé is more correct.

NOTE: This answer is translated from my original post (in Japanese).

I guess fixest package have no options for the cross references on Rmd. Although it may be a kind of kludge, I found that you can insert LaTeX command in the title argument like the following.

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

Addendum: In general, bookdown doesn't support to refer to the tables by the chunk labels, only to plots. Other packages (e.g. officedown) can refer to the table by the chunk labels.

You can also use stargazer pacakge to tabulate the result of regression analysis easily, but you may need some tricks too (see https://github.com/rstudio/bookdown/issues/175).

Solution 2:

etable has a label argument:

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}