lrberge / fixest

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

Unclear error message when using `i(bin = )` #525

Open statzhero opened 2 months ago

statzhero commented 2 months ago

This is based on the example from the docs.

library(fixest)
data(base_stagg)

res_twfe = feols(y ~ x1 + i(time_to_treatment, ref = c(-1, -1000)) | id + year, base_stagg)

When using a global variable to set the bin or related sunab(bin.rel = ) argument, I get an error that seems not quite appropriate?


BINS <- c(-1:-4)
res_twfe = feols(y ~ x1 + i(time_to_treatment, ref = c(-1, -1000), bin = BINS) | id + year, base_stagg)

# works
summary(res_twfe)

BINS <- c(-1:-5)
res_twfe = feols(y ~ x1 + i(time_to_treatment, ref = c(-1, -1000), bin = BINS) | id + year, base_stagg)
# Error in feols(y ~ x1 + i(time_to_treatment, ref = BINS) | id + year,  : 
#   The variable 'BINS' is in the RHS (first part) of the formula but not in the data set.

res_twfe = feols(y ~ x1 + i(time_to_treatment, ref = c(-1, -1000), bin = c(-1:-5)) | id + year, base_stagg)
# works again
summary(res_twfe)