bcallaway11 / did

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

Error in family$linkfun(mustart) #153

Closed PhantomKidding closed 9 months ago

PhantomKidding commented 1 year ago

I'm running into the error below when calling the att_gt() function.

Error in family$linkfun(mustart) : Argument mu must be a nonempty numeric vector

I walked through your source code (version 2.1.2) and found the problem is caused by line 76 at compute.att_gt() function. disdat <- data[data[, tname] == tlist[t + tfac] | data[, tname] == tlist[pret], ] If disdat is empty, then the glm at line 101 will throw the error.

Any quick fix for it?

Thanks in advance.

bcallaway11 commented 1 year ago

Hi, thanks for the message. Do you have an example that you could send me where this issue comes up?

Thanks, Brant

PhantomKidding commented 1 year ago

Thanks for responding promptly. I attached the anonymized data and used the following code. data.csv

data = read.csv('data.csv')
m <- att_gt(yname = "y",
             tname = "time",
             idname = "id",
             gname = "first",
             xformla = ~a+b+c+d+e+f+g,
             data = data,
             control_group = "notyettreated",
             panel=T
             , pl=T, cores=8
             , alp=0.05
)
bcallaway11 commented 1 year ago

Hello, I quickly looked through this, and I think the issues are mainly related to small group sizes and lack of variation in the covariates. Also, given that the data is an unbalanced panel, I'd recommend adding the argument allow_unbalanced_panel=TRUE. For example, the following code runs for me

m <- att_gt(yname = "y",
            tname = "time",
            idname = "id",
            gname = "first",
            xformla = ~1, #~a+b+c+d+e+f+g,
            data = data,
            control_group = "notyettreated",
            panel=T, allow_unbalanced_panel = T
            , pl=T, cores=1
            , alp=0.05
)

aggte(m, type="dynamic", na.rm=TRUE)

though I notice that if I include any covariates, I get errors about no variation in the covariates within groups, this would mean that it is infeasible to include those covariates.

Hope this helps, Brant