insongkim / wfe

20 stars 4 forks source link

floating point exception error #3

Closed letitbk closed 5 years ago

letitbk commented 5 years ago

Hi, thanks for your excellent package! I am using your wfe package to run weighted two-way fixed effects models. When I run the following model, I get the following error message.

library(wfe)
Y = c(0.4335664, 0.5740741, 0.5944056, 0.5882353, 0.5321637, 0.6064516, 0.5165289, 0.6779661)
treatment = c(0,0,1,0,0,0,0,0)
group = as.factor(c(rep("A",4),rep("B",4)))
time = as.factor(rep(c(1,2,3,4),2))

test_data = data.frame(Y,treatment,group,time)

wfe(as.formula("Y ~ treatment"), data = test_data, treat = "treatment",
        unit.index = "group", time.index ="time", method = "unit", unweighted=FALSE, 
        qoi = "att", estimator ="did", hetero.se=TRUE, auto.se=TRUE,unbiased.se=TRUE,
        White = TRUE, White.alpha = 0.05, verbose = TRUE)

The following error message also occurs when I increase the number of groups. Can you check about this? I am currently using the version 1.8.

Number of unique unit is 2 
Weight calculation started Floating point exception: 8
insongkim commented 5 years ago

Thanks, @letitbk. This error was due to the division of small integer numbers in one of the printout statements. The error is now fixed in version 1.9.1 which will be available soon on CRAN as well. In the meantime, setting verbose = FALSE will let you run the code without the error.

letitbk commented 5 years ago

thanks a lot -- but here's the error message that I've seen when I set verbose = FALSE.

Warning messages:
1: In sqrt(diag(vcov.wfe)) : NaNs produced
2: In sqrt(diag(var.cov.fe)) : NaNs produced

This is related to what you mentioned about the division of small integer numbers, I guess!

insongkim commented 5 years ago

This is due to the fact that X'WX is not full rank in this toy example. We plan to insert an additional warning message in the next update. Could you set White = FALSE?

letitbk commented 5 years ago

I still got the same warning message from this toy example, but this warning message did not appear in my main data. Your explanation makes senses to me. I guess this issue can be closed for this moment. I will report again if I find another issue. Thanks again!