lrberge / fixest

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

Issue with `Inf` in iplot #512

Open kylebutts opened 1 week ago

kylebutts commented 1 week ago

This code (correctly) will not plot because one of the values of x2 is Inf which does not work with xlim (plot.window(...) : need finite 'xlim' values).

This comes up for me when creating a event-study dummies (E.g. never_treated has year_treated = Inf; rel_year = year - year_treated = -Inf).

I'm raising this as an issue b/c I don't know what the best fix would be on fixest's end.

Two user-land fixes could be:

  1. manually change the value from -Inf to -100 or something, but this would make the figure look weird. So, user would have to chose like min - 1 or something which is a pain.
  2. Use drop = "Inf". This is probably the best answer, but the docs do not mention for iplot the values not the normal x2::Inf" regex. As an aside, could we add the error note to the documentation? "Note that in iplot, the variables names are the values that should be in the x-axis."
library(fixest)
data <- data.frame(x1 = runif(100),  x2 = sample(c(1, 2, Inf), 100, replace = TRUE))
data$y <- data$x1 * 2 + rnorm(100)

est = feols(y ~ x1 + i(x2, ref = Inf), data = data)
iplot(est)
#> Error in plot.window(...): need finite 'xlim' values
lrberge commented 1 week ago

Hi Kyle: IYO what should be the expected output?

I agree with the other points: the doc isn't clear + the error message is arcane.