lrberge / fixest

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

Different Outputs from print(model) - print(model$coeftable) #495

Closed bellodi92 closed 1 month ago

bellodi92 commented 2 months ago

As always, thanks for the great package!

Is it ok that these two commands return different outputs?

library(fixest)

d = datasets::airquality

m = feols(Wind ~ Solar.R | Day, d)

print(m$coeftable)

print(m)

In print(m$coeftable), se = "iid"

In print(m), cluster = ~ Day

fixest version ‘0.11.2’

lrberge commented 2 months ago

Hi, thanks!

Yes, this is normal. The SEs are not pre-computed since this is costly, so if the argument vcov has not been explicitly provided during the call, the SEs of the object fixest_estimation$coeftable has always iid SEs.

In general the elements from the list returned shouldn't be accessed directly, user-level functions are safer to use. Here, use coeftable which, btw, also works with multiple estimations:

est = feols(Wind ~ Solar.R | Day, airquality)
# NOTE: 7 observations removed because of NA values (RHS: 7).
coeftable(est)
#             Estimate  Std. Error    t value  Pr(>|t|)
# Solar.R -0.001769902 0.004775865 -0.3705929 0.7135447
# attr(,"type")
# [1] "Clustered (Day)"

est_mult = feols(Wind ~ Solar.R | Day, airquality, 
                 split = ~bin(Month, .("<=July" = 5:6, ">=Aug." = 7:9)))
# NOTE: 7 observations removed because of NA values (RHS: 7).
coeftable(est_mult)
#>   id sample.var sample coefficient      Estimate  Std. Error     t value  Pr(>|t|)
#> 1  1      Month <=July     Solar.R  0.0004119067 0.008495095  0.04848759 0.9616490
#> 2  2      Month >=Aug.     Solar.R -0.0059763158 0.006253689 -0.95564641 0.3468888

Although this is mentioned in the docs:

Note that fixest objects contain many elements and most of them are for internal use, they are presented here only for information. To access them, it is safer to use the user-level methods (e.g. vcov.fixest, resid.fixest, etc) or functions (like for instance fitstat to access any fit statistic).

... it's not super clear what it entails and maybe should be written explicitly for the slot coeftable since it is a popular element. I'll amend that.

bellodi92 commented 1 month ago

Got it, thanks :)