lrberge / fixest

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

remove column numbers and add line to etable #453

Open nkarwowski opened 7 months ago

nkarwowski commented 7 months ago

Hello fixest team, Thank you for your awesome package!

  1. I wanted to reach out and ask whether it is possible to remove the column numbers in the etable header? I have played around with style.tex and model.format but have been unable to get rid of the numbered header on my own.

  2. Also, how can I add a solid black line before the fixed effects section? I am trying to add a line between the adjusted R squared line and before the section that lists the fixed effects at the end.

Thanks so much for any guidance that you can provide!

Best, Nicole

I attached all of the code and dataset I used to build my table in a zipped folder.

Here is the fixest etable code I used and the table it outputs:

fixest::etable(p1, p2, p3, p1u, p2u, p3u, depvar = FALSE, tex=TRUE, digits=3, fitstat=c("my", "n", "ar2"), keep=c("restored", "upstream"), style.tex=fixest::style.tex("aer", line.top ="", var.title = "$\textbf{Panel B: phosphorous}$"), extralines=list("__ "=c(" ", " ", " ", " ", " ", " "), "^^ "=c(" ", " ", " ", " ", " ", " ")))

\begingroup \centering \begin{tabular}{lcccccc} & (1) & (2) & (3) & (4) & (5) & (6)\
$\textbf{Panel B: phosphorous}$\ & & & & & & \
restored wetland (prop) & -0.147 & -0.041 & -0.206 & 0.422 & -0.369 & 0.118\
& (0.156) & (0.162) & (0.249) & (0.505) & (0.420) & (0.845)\
upstream restored wetland (prop) & & & & -0.329 & -0.828 & -0.093\
& & & & (0.779) & (0.703) & (1.15)\
\ Dependent variable mean & 0.15232 & 0.15232 & 0.15232 & 0.14159 & 0.14159 & 0.14159\
Observations & 7,226 & 7,226 & 7,226 & 2,133 & 2,133 & 2,133\
Adjusted R$^2$ & 0.44446 & 0.49193 & 0.45868 & 0.40184 & 0.45014 & 0.40815\
& & & & & & \
\ HUC8 fixed effects & $\checkmark$ & & $\checkmark$ & $\checkmark$ & & $\checkmark$\
year fixed effects & $\checkmark$ & $\checkmark$ & & $\checkmark$ & $\checkmark$ & \
month fixed effects & $\checkmark$ & $\checkmark$ & & $\checkmark$ & $\checkmark$ & \
HUC12 fixed effects & & $\checkmark$ & & & $\checkmark$ & \
HUC4 x year fixed effects & & & $\checkmark$ & & & $\checkmark$\
\bottomrule \end{tabular} \par\endgroup

github.zip

Oravishayrizi commented 7 months ago

Hi,

1) To remove the column numbers in the etable header, you can use the postprocess.tex argument with a custom function. This method works, but there might be more straightforward solutions that I'm not aware of. Here's a function that can help with your specific requirement:

remove_model_numbers <- function(tab) {
    # Remove lines starting specifically with & (1) & (2)
    tab <- gsub("^\\s*& \\(1\\) & \\(2\\).*\n", "", tab, perl = TRUE)
    return(tab)
}

Apply this function in your etablecall like so: etable(p1, p2, p3, p1u, p2u, p3u, headers=NULL, ..., postprocess.tex = remove_model_numbers)

2)For adding a solid black line before the fixed effects section, it seems you have it right with fixef.title = "\\midrule" in your style.tex argument.

To have both you can do something like that:

remove_model_numbers <- function(tab) {
    # Remove lines starting specifically with & (1) & (2)
    tab <- gsub("^\\s*& \\(1\\) & \\(2\\).*\n", "", tab, perl = TRUE)
    return(tab)
}

etable(p1, p2, p3, p1u, p2u, p3u, headers=NULL,
               depvar = FALSE,
               tex=TRUE, digits=3, fitstat=c("my", "n", "ar2"), 
               keep=c("restored", "upstream"),
               style.tex=fixest::style.tex("aer", line.top ="",
                                           fixef.title = "\\midrule", #Add mid-rule before fixed-effects
                                           var.title = "$\\textbf{Panel B: phosphorous}$"),
               extralines=list("__ "=c(" ", " ", " ", " ", " ", " "),
                               "^^  "=c(" ", " ", " ", " ", " ", " ")),
       postprocess.tex = remove_model_numbers) # Remove a line that start with &(1)&(2)
nkarwowski commented 7 months ago

Thanks so much for taking the time to respond. This works great! The table is perfect.