bacondecomp icon indicating copy to clipboard operation
bacondecomp copied to clipboard

Dependent variable is a constant error, when it is not.

Open perodmar opened this issue 2 years ago • 5 comments

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

  1. Is there a way to feed the feols result directly into the bacon function?
  2. Why does that error keep coming up? How to handle it?

Thank you!

perodmar avatar May 24 '23 16:05 perodmar

Hi @perodmar, the problem (I think) is that for some of the 2x2s, your outcome variable is constant

kylebutts avatar May 24 '23 18:05 kylebutts

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 avatar May 24 '23 18:05 perodmar

@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!

kylebutts avatar May 25 '23 02:05 kylebutts

No worries! I'll look through the code. Hopefully someone can figure it out in the meantime...Thanks for the help @kylebutts.

perodmar avatar May 25 '23 22:05 perodmar

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

Weijia11 avatar Oct 06 '23 02:10 Weijia11