lrberge / fixest

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

Feature Request: adding `interaction.order` argument to `coeftable` #380

Open Oravishayrizi opened 1 year ago

Oravishayrizi commented 1 year ago

Following issue #120, I wondered whether it is possible to implement the argument interaction.order to the function coeftable as well.

When the order of variables changes, it raises difficulties to extract the coefficients manually (which I often use to present the estimation results in figures)

Here is a reprex:

library(fixest)
packageVersion('fixest')
#> [1] '0.11.1'

fit = feols(Sepal.Width ~ Sepal.Length*Species + Petal.Width*Species , iris)

#Without ordering
etable(fit,keep = "x")
#>                                                  fit
#> Dependent Var.:                          Sepal.Width
#>                                                     
#> Sepal.Length x Speciesversicolor -0.6487*** (0.1337)
#> Sepal.Length x Speciesvirginica  -0.6215*** (0.1204)
#> Speciesversicolor x Petal.Width     0.7497. (0.4126)
#> Speciesvirginica x Petal.Width       0.4194 (0.3771)
#> ________________________________ ___________________
#> S.E. type                                        IID
#> Observations                                     150
#> R2                                           0.69010
#> Adj. R2                                      0.67251
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftable(fit,keep = ":")
#>                                  Estimate Std. Error   t value     Pr(>|t|)
#> Sepal.Length:Speciesversicolor -0.6486831  0.1336798 -4.852512 3.189025e-06
#> Sepal.Length:Speciesvirginica  -0.6214732  0.1203549 -5.163670 8.091816e-07
#> Speciesversicolor:Petal.Width   0.7497129  0.4125538  1.817249 7.130238e-02
#> Speciesvirginica:Petal.Width    0.4193725  0.3770745  1.112174 2.679559e-01

#with ordering
etable(fit,interaction.order ="Species",keep = "x")
#>                                                  fit
#> Dependent Var.:                          Sepal.Width
#>                                                     
#> Speciesversicolor x Sepal.Length -0.6487*** (0.1337)
#> Speciesvirginica x Sepal.Length  -0.6215*** (0.1204)
#> Speciesversicolor x Petal.Width     0.7497. (0.4126)
#> Speciesvirginica x Petal.Width       0.4194 (0.3771)
#> ________________________________ ___________________
#> S.E. type                                        IID
#> Observations                                     150
#> R2                                           0.69010
#> Adj. R2                                      0.67251
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftable(fit,interaction.order ="Species",keep = ":")
#>                                  Estimate Std. Error   t value     Pr(>|t|)
#> Sepal.Length:Speciesversicolor -0.6486831  0.1336798 -4.852512 3.189025e-06
#> Sepal.Length:Speciesvirginica  -0.6214732  0.1203549 -5.163670 8.091816e-07
#> Speciesversicolor:Petal.Width   0.7497129  0.4125538  1.817249 7.130238e-02
#> Speciesvirginica:Petal.Width    0.4193725  0.3770745  1.112174 2.679559e-01