lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
361 stars 59 forks source link

Order of fixed-effect terms in LaTeX table #432

Open vronizor opened 11 months ago

vronizor commented 11 months ago

Hi! Thanks for the wonderful package :)

I'm customizing my tables and couldn't find an option to specify the order of display of fixed-effect terms in a LaTeX table. order seems to only impact variables — it would be nice to have a fixef.order argument that works similarly.

etiennebacher commented 11 months ago

To add more information, it is possible to specify the order using fixef.group. However, this only works in the default "console" format, it doesn't work with tex = TRUE:

library(fixest)
packageVersion("fixest")
#> [1] '0.11.1'

res = feols(mpg ~ drat + hp | cyl + am, mtcars)

### default shows "cyl" first, then "am"
etable(res)
#>                               res
#> Dependent Var.:               mpg
#>                                  
#> drat              0.8399 (0.5452)
#> hp              -0.0452. (0.0147)
#> Fixed-Effects:  -----------------
#> cyl                           Yes
#> am                            Yes
#> _______________ _________________
#> S.E.: Clustered           by: cyl
#> Observations                   32
#> R2                        0.82675
#> Within R2                 0.26240
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

### override the order
etable(res, fixef.group = list(am = "am", cyl = "cyl"))
#>                               res
#> Dependent Var.:               mpg
#>                                  
#> drat              0.8399 (0.5452)
#> hp              -0.0452. (0.0147)
#> Fixed-Effects:  -----------------
#> am                            Yes
#> cyl                           Yes
#> _______________ _________________
#> S.E.: Clustered           by: cyl
#> Observations                   32
#> R2                        0.82675
#> Within R2                 0.26240
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

### but the order doesn't change in TeX output
etable(res, fixef.group = list(am = "am", cyl = "cyl"), tex = TRUE)
#> \begingroup
#> \centering
#> \begin{tabular}{lc}
#>    \tabularnewline \midrule \midrule
#>    Dependent Variable: & mpg\\  
#>    Model:              & (1)\\  
#>    \midrule
#>    \emph{Variables}\\
#>    drat                & 0.8399\\   
#>                        & (0.5452)\\   
#>    hp                  & -0.0452$^{*}$\\   
#>                        & (0.0147)\\   
#>    \midrule
#>    \emph{Fixed-effects}\\
#>    cyl                 & Yes\\  
#>    am                  & Yes\\  
#>    \midrule
#>    \emph{Fit statistics}\\
#>    Observations        & 32\\  
#>    R$^2$               & 0.82675\\  
#>    Within R$^2$        & 0.26240\\  
#>    \midrule \midrule
#>    \multicolumn{2}{l}{\emph{Clustered (cyl) standard-errors in parentheses}}\\
#>    \multicolumn{2}{l}{\emph{Signif. Codes: ***: 0.01, **: 0.05, *: 0.1}}\\
#> \end{tabular}
#> \par\endgroup