Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
perodmar opened this issue May 24, 2023 · 5 comments
Open

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

perodmar opened this issue May 24, 2023 · 5 comments

Comments

@perodmar
Copy link

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!

@kylebutts
Copy link
Collaborator

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

@perodmar
Copy link
Author

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.

@kylebutts
Copy link
Collaborator

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

@perodmar
Copy link
Author

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

@Weijia11
Copy link

Weijia11 commented Oct 6, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants