lrberge / fixest

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

Latex issue in `esttex()` with "F-test (1st stage)" fit statistics and snake case variable #505

Closed MaelAstruc closed 3 weeks ago

MaelAstruc commented 1 month ago

Hello,

Sorry to spam the issues, but I think I have another bug with the esttex() function. When I want to include the "ivf" fit statistics and my variable includes a "_", the character doesn't seem to be properly escaped in the latex output.

Here is a short reproducible example:

N <- 1000

df <- data.frame(
  z = runif(N),
  e1 = rnorm(N),
  e2 = rnorm(N)
)

df$x_ <- 1 + 2 * df$z + df$e1
df$y <- 3 + 4 * df$x + df$e2

fixest::feols(y ~ 1 | x_ ~ z, data = df) |>
  fixest::esttex(fitstat = "ivf")

# \begin{table}[htbp]
#   \caption{no title}
#   \centering
#   \begin{tabular}{lc}
#     \tabularnewline \midrule \midrule
#     Dependent Variable:    & y\\  
#     Model:                 & (1)\\  
#     \midrule
#     \emph{Variables}\\
#     Constant               & 2.957$^{***}$\\   
#                            & (0.1141)\\   
#     x\_                    & 4.013$^{***}$\\   
#                            & (0.0534)\\   
#     \midrule
#     \emph{Fit statistics}\\
#     F-test (1st stage), x_ & 393.88\\  
#     \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}

The variable name is properly escaped in the results, but not in the fit statistics. I think this could be fixed when parsing the fit statistics parameters in results2formattedList() in the function funrename() line 1252 to 1258. You could check if the output is in latex format and use escape_latex() on the variable name if so.

If this makes sense, I can write a short PR to change it.

lrberge commented 1 month ago

Hi Mael: the changes look targeted, minor, and with no side effect (it seems). That's a strong case for a PR :-) Yep, please do if you have the time, thanks.

By the way: fyi I'm not developing the etable function anymore because I want to change the underlying technology. It will (should) be much more powerful and solve numerous (all?) problems down the road. The issue is... that I'm not done with this new tech yet! That's why there are so many issues related to etable still open, and why I'm reluctant to work on them.

MaelAstruc commented 3 weeks ago

Hi Laurent, I have submitted a short PR for this change.

I'm looking forward to the new version of etable, good luck with it.

lrberge commented 3 weeks ago

Merged the PR, closing then.