lrberge / fixest

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

Bug in `esttex()` when p-value < 2.2e-16 #504

Closed MaelAstruc closed 3 weeks ago

MaelAstruc commented 1 month ago

Hello,

I have an issue with the esttex() function and the fit statistics of an IV. More precisely, when I want to include a Wu-Hausman endogeneity test using fitstat = "wh.p", it prints $NaN\times 10^{-Inf}$.

I looked a bit into it and the issue seems to come from the formatting of the results when the p-value is too small. Here is a reproducible example:

# Here is what I have
y <- fixest::fitstat(results,  "wh.p", etable = TRUE, verbose = FALSE)
str(y)
# List of 1
#  $ wh.p: num 0

# You can start from here
y <- list(wh.p = 0)

fixest:::format_number(y)
#       wh.p 
# "NaNe-Inf" 

# To mimic the sapply function in format_number()
x <- unlist(y)

fixest:::format_nber_single(x, digits = 2)
# [1] "NaNe-Inf"

# The culprit is line 19 of format_nber_single()
floor(log10(abs(x)))
# wh.p 
# -Inf 

I think there should be a check to handle the case where x == 0, maybe after the checks at the beginning of the function. Regarding the formatting:

If I understood the issue correctly and one of the solutions sounds good to you, I can write a short PR.

lrberge commented 3 weeks ago

Thanks for the report, now fixed.