estimatr icon indicating copy to clipboard operation
estimatr copied to clipboard

faulty fits with small N and many interactions

Open graemeblair opened this issue 2 years ago • 1 comments

@jwbowers and Lula Chen reported that with small N and many values of a discrete covariate lm_lin does not return an answer. I reproduced it below, and it is not specific to lm_lin. lm does return an answer in this kind of setting.

library(estimatr)
library(fabricatr)

dat <-
  fabricate(
    N = 50,
    x = sample(1:40, N, replace = TRUE),
    potential_outcomes(Y ~ 0.1 * Z + x + rnorm(N)),
    Z = sample(0:1, N, replace = TRUE),
    Y = reveal_outcomes(Y ~ Z)
  ) 

# doesn't return a 
lm_lin(Y ~ Z, covariates = ~as.factor(x), data = dat)

# same problem if we include covariate dummies
lm_robust(Y ~ Z + as.factor(x), data = dat)

# lm estimates
summary(lm(Y ~ Z*as.factor(x), data = dat))

graemeblair avatar Jul 06 '22 02:07 graemeblair

I think it's related to the robust std errors, works fine when you turn them off:

lm_robust(Y ~ Z + as.factor(x), data = dat, se='classical')

nfultz avatar Jul 06 '22 15:07 nfultz