Skip to content

Display exact p-values in `etable' #590

@Oravishayrizi

Description

@Oravishayrizi

Hello Laurent,

A journal asked me to report all my tables with exact p-values instead of the usual asterisk pattern for 0.01, 0.05, 0.1.

According to the documentation:

The coefstat parameter accepts only one of: "se" (default), "tstat", or "confint".

I need to display coefficients, standard errors, and exact p-values in my regression tables, so I'm thinking of something like:
coefstat = c("coef", "se", "p")

I couldn't find a way to do this in fixest. As always, if I missed something that's already available, I apologize.

If this isn't possible right now, I'll handle it using postprocess.tex, but this seems a bit hacky, so I'd prefer to avoid it if there's a cleaner solution.

library(fixest)
data("iris")

# Fit a linear regression model using fixest
model1 <- feols(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width, data = iris)
model2 <- feols(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width | Species, data = iris)


# Replace stars with p-values
sign_dict<-seq(0,1,by=0.001)
names_dict<-paste0(",p<",sign_dict)
names(sign_dict) <- names_dict


rm_signif_legend<- function(tab) {
    # Remove the line that include the text " Signif. codes:"
    tab <- tab[!grepl("Signif", tab)]
    # Replace $^{,p<0.1}$ with (p<0.1)
    tab <- gsub("\\$\\^\\{,p<([0-9.]+)\\}\\$", "$p<\\1$", tab)
    return(tab)
}

etable(model1, model2, 
       title = "Linear Regression Models for Sepal Length",
       digits = 3,
       signif.code = sign_dict,
       postprocess.tex = rm_signif_legend,
       tex=TRUE
       )

Which returns:

\begin{table}[htbp]
   \caption{Linear Regression Models for Sepal Length}
   \centering
   \begin{tabular}{lcc}
      \tabularnewline \midrule \midrule
      Dependent Variable: & \multicolumn{2}{c}{Sepal.Length}\\
      Model:       & (1)             & (2)\\
      \midrule
      \emph{Variables}\\
      Constant     & 1.86, p<0.001   &   \\
                   & (0.251)         &   \\
      Sepal.Width  & 0.651, p<0.001  & 0.496, p<0.055\\
                   & (0.067)         & (0.121)\\
      Petal.Length & 0.709, p<0.001  & 0.829, p<0.014\\
                   & (0.057)         & (0.097)\\
      Petal.Width  & -0.556, p<0.001 & -0.315, p<0.103\\
                   & (0.128)         & (0.110)\\
      \midrule
      \emph{Fixed-effects}\\
      Species      &                 & Yes\\  
      \midrule
      \emph{Fit statistics}\\
      Observations & 150             & 150\\
      R$^2$        & 0.85861         & 0.86731\\
      Within R$^2$ &                 & 0.65201\\
   \end{tabular}
\end{table}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions