bacondecomp
bacondecomp copied to clipboard
Dependent variable is a constant error, when it is not.
First, thank you for the great work with the package and adopting feols. Really useful!
I am trying to use the bacon function but I keep getting the error that the dependent variable is a constant, when it is not:
bacon(n_tot ~ tt, data = panel[panel$random==1,],
+ id_var = "id_grid",
+ time_var = "period",
+ quietly = TRUE)
Error in fixest::feols(outcome ~ treated | time + id, data = data1) :
The dependent variable is a constant. The estimation with fixed-effects cannot be done.
I assume it has to do with the fact that I have lots of zeros, but around 5% are non-zeros:
quantile(panel[panel$random==1,]$n_tot,seq(0.95,1,0.01))
95% 96% 97% 98% 99% 100%
0.0000000 0.9677419 0.9677419 1.0000000 1.0714286 8.7096774
It seems to be a bacon function error since it runs smoothly when I use feols directly:
feols(as.formula("n_tot ~ tt | id_grid + period"), data=panel[panel$random==1,])
OLS estimation, Dep. Var.: n_tot
Observations: 457,125
Fixed-effects: id_grid: 6,625, period: 69
Standard-errors: Clustered (id_grid)
Estimate Std. Error t value Pr(>|t|)
tt -0.003755 0.002513 -1.49411 0.13519
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
RMSE: 0.250655 Adj. R2: 0.20454
Within R2: 1.141e-5
- Is there a way to feed the feols result directly into the bacon function?
- Why does that error keep coming up? How to handle it?
Thank you!
Hi @perodmar, the problem (I think) is that for some of the 2x2s, your outcome variable is constant
Ok, I see. That would make sense. @kylebutts is there a way to either 1) drop those comparisons or 2) force the estimation? If you do not have variation on outcomes then that coefficient would still be 0.
@perodmar Probably not an easy way to do this within the package. Almost always, this should be a true error that someone accidentally passed a constant variable as the outcome (your case being the exception). However, the code is not too complicated without covariates, I'm sure you could copy the few functions and change it to how you need it. I think putting a 0 as the 2x2 treatment estimate sounds right to me
Sorry I can't be of more help!
No worries! I'll look through the code. Hopefully someone can figure it out in the meantime...Thanks for the help @kylebutts.
Hi, I met the same error when I added the control variable, did you figure out how to fix this problem? I changed other control variables, it still reported this error... @perodmar