lrberge / fixest

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

update() to add fixed effects fails if no fixed effects exist originally #475

Closed hughjonesd closed 4 months ago

hughjonesd commented 4 months ago

Here's a test case:

dat <- data.frame(a = rnorm(10), b = rnorm(10), c = rep(1:2, 5))
mod <- feols(a ~ b, data = dat)
mod2 <- feols( a ~ b | c, data = dat)

update(mod, . ~ . | c)
# Error in update.default(fixef_old, fixef_new_fml) : 
#   need an object with call component

update(mod, . ~ .) # works
update(mod2, . ~ . | . - c) # works
update(mod2, . ~ . | .) # works

I'd expect the first call to work and give the same result as mod2.

Fixest version 0.11.2.

hughjonesd commented 4 months ago

A workaround seems to be:

mod3 <- feols(a ~ b | 1, data = dat)  # gives same result as `mod`
update(mod3, . ~ . | . + c) # works
lrberge commented 4 months ago

Thanks for the clear issue. Fixed.