lrberge / fixest

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

Get esttex to respect common dict aliases #12

Closed grantmcdermott closed 4 years ago

grantmcdermott commented 4 years ago

As promised, a second esttex issue...

Is it possible for esttex output to respect common (i.e. unique) dictionary aliases?

I often want to output similar variables on the same row in a regression table. For instance, to make them immediately comparable even if they are named differently in my actual R model calls. The way this works for other regression outputting packages in R (e.g. huxtable or stargazer) is to give them the same alias. However, that strategy does not appear to work here.

Consider the following example, where I want to compare full vs partial marginal effects, using different model syntax. The coefficient on Wind in mod_2 is actually the same as Month5:Wind in mod_1. Yet, even if I explicitly give it the same alias, the two coefficients are still printed on separate rows.

library(fixest)

aq = airquality
aq$Month = factor(aq$Month)

## Full marginal effects
mod_1 = feols(Ozone ~ Month / Wind, data = aq)
#> NOTE: 37 observations removed because of NA values (Breakup: LHS: 37, RHS: 0).

## Partial marginal effects
mod_2 = feols(Ozone ~ Month * Wind, data = aq)
#> NOTE: 37 observations removed because of NA values (Breakup: LHS: 37, RHS: 0).

## "Wind" in mod_2 is actual "Month5:Wind"...
myDict = c("Wind" = "Month5:Wind")

## Doesn't work as expected: Get separate "Month5:Wind" rows instead of one.
esttex(
  mod_1, mod_2, titles  = c("Full MEs", "Partial MEs"),
  dict = myDict,
  drop = c("Int", paste0("Month", 6:9)) ## Optional: Just to highlight rows of interest 
)
#> \begin{table}[htbp]\centering
#> \caption{no title}
#> \begin{tabular}{lcc}
#>  & & \tabularnewline
#> \hline
#> \hline
#> Dependent Variable:&\multicolumn{2}{c}{Ozone}\\
#> Model:&(1)&(2)\\
#> \hline
#> \emph{Variables}\tabularnewline
#> Month5:Wind&-2.3681$^{*}$&  \\
#>   &(1.3162)&  \\
#> Month5:Wind&  &-2.3681$^{*}$\\
#>   &  &(1.3162)\\
#> \hline
#> \emph{Fit statistics}&  & \\
#> Observations& 116&116\\
#> R$^2$ & 0.54732&0.54732\\
#> Adjusted R$^2$ & 0.50889&0.50889\\
#> \hline
#> \hline
#> \multicolumn{3}{l}{\emph{Normal standard-errors in parentheses. Signif Codes: ***: 0.01, **: 0.05, *: 0.1}}\\
#> \end{tabular}
#> \end{table}

Created on 2019-12-29 by the reprex package (v0.3.0)

lrberge commented 4 years ago

Hi again,

The issue you mention is a big problem indeed--the output is really not appropriate. I'll correct it next week.

Thanks for raising it!

lrberge commented 4 years ago

I'm closing it, I've updated the package accordingly.