lrberge / fixest

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

Option to have na.action=na.exclude #385

Closed tudorschlanger closed 5 months ago

tudorschlanger commented 1 year ago

I am having issues with the size of the residuals vectors from an estimation. It does not correspond to the data frame size since there are NA values which are ignored.

The issue is better explained here: https://stackoverflow.com/questions/6882709/how-do-i-deal-with-nas-in-residuals-in-a-regression-in-r

The solution in lm package is to have na.action=na.exclude.

Could you also implement this? It would be very useful. Thank you!

kylebutts commented 1 year ago

resid(mod, na.rm = FALSE) works as you are hoping

lrberge commented 5 months ago

Hi, @kylebutts got you covered. Thanks Kyle.

base = setNames(iris, c("y", "x1", "x2", "x3", "species"))
base$y[1:5] = NA

est = feols(y ~ x1, base)

length(resid(est))
# 145
length(resid(est, na.rm = FALSE))
# 150