bcallaway11 / did

Difference in Differences with Multiple Periods, website: https://bcallaway11.github.io/did
287 stars 91 forks source link

Error in solve.default(crossprod(wols.x.pre.treat, int.cov)/n) #154

Open XiangShawnZhang opened 1 year ago

XiangShawnZhang commented 1 year ago

Hi there, thanks a lot for the great package! I ran into a question when I wanted to add one control variable in the regression while allowing the unbalanced panel.

This code on the household-lelvel data works well: reg1 <- att_gt(yname = "y", tname = "year", idname = "id", gname = "first.treat", xformla = ~ x1 + x2, allow_unbalanced_panel = T, control_group = "notyettreated",
data = dataset1) When I want to add a district-level control variable: reg2 <- att_gt(yname = "y", tname = "year", idname = "id", gname = "first.treat", xformla = ~ x1 + x2 + District, allow_unbalanced_panel = T, control_group = "notyettreated",
data = dataset1) it popped up an error of Error in solve.default(crossprod(wols.x.pre.treat, int.cov)/n) : Lapack routine dgesv: system is exactly singular: U[4,4] = 0

Then we I set the option of allow_unbalanced_panel = F, the code works again: reg3 <- att_gt(yname = "y", tname = "year", idname = "id", gname = "first.treat", xformla = ~ x1 + x2 + District, allow_unbalanced_panel = F, control_group = "notyettreated",
data = dataset1) There is no severe multicollinearity, is there a reason for this? Thanks for your help!

effedp commented 1 year ago

I am experiencing the very same issue when I include a province time-invariant control in xformla. I checked out that it is varying "enough" within cohorts so as not to mess up with the psm, and there seems to be no problem. Any suggestion? Thank you for being so helpful!

bcallaway11 commented 1 year ago

@XiangShawnZhang, sorry for not replying to this originally. I am unsure about this source of this one. Do either of you have code that you could send me to reproduce the error? My email address is brantly.callaway@uga.edu.

effedp commented 1 year ago

Hi @bcallaway11, thank you for the answer. I can email you my code without a problem, but I am running it on administrative data I can't share. So you won't be able to reproduce the error directly. Would it still be helpful for you?

bholtdwyer commented 1 year ago

I'm having the same problem; sending an email with my code and .RDS file of the dataset it's having trouble with. Thanks for making this package available!

XiangShawnZhang commented 10 months ago

Hi, I just want to note a potential cause of this issue: in my case, there are not many variabilities for some variables, which leads to exactly singular in some (g,t) groups. Hope this helps!