xuyiqing / gsynth

Generalized Synthetic Control Method
Other
132 stars 40 forks source link

Error in inter_fe(Y = Y.co, X = X.co, r, force = force, beta0 = beta0, : Mat::head_cols(): size out of bounds #32

Open IdaHjermitslev opened 4 years ago

IdaHjermitslev commented 4 years ago

Dear Professor Xu

Thank you for your work on the generalised synthetic control method.

I am trying to use the gsynth package as specified in the examples, but I am running into an error that I cannot resolve. I have verified that my dataset matches the examples provided in the package.

I am providing the dataset, example code and the error I am getting.

I am using R version 3.4.0 and gsynth version 1.1.4.

Code:

library(gsynth)

data <- readRDS("data.rds")

out <- gsynth(Y ~ D + X1 + X2, data = data, index = c("id", "time"), 
              force = "two-way", CV = TRUE, r = c(0, 5), se = TRUE, inference = "parametric", 
              nboots = 1000, parallel = FALSE)

Error:

> out <- gsynth(Y ~ D + X1 + X2, data = data, index = c("id", "time"), 
+               force = "two-way", CV = TRUE, r = c(0, 5), se = TRUE, inference = "parametric", 
+               nboots = 1000, parallel = FALSE)
Cross-validating ... 
 r = 0; sigma2 = 0.10361; IC = -0.63150; PC = 0.07677; MSPE = 0.09995*
 r = 1; sigma2 = 0.06434; IC = 0.48180; PC = 0.36854; MSPE = 0.10280
 r = 2; sigma2 = 0.04634; IC = 1.72070; PC = 0.49677; MSPE = 0.12504
 r = 3; sigma2 = -0.00000; IC = NaN; PC = -0.00000; MSPE = 0.08032*
 r = 4; sigma2 = -0.00000; IC = NaN; PC = -0.00000; MSPE = Inf

error: Mat::head_cols(): size out of bounds
Error in inter_fe(Y = Y.co, X = X.co, r, force = force, beta0 = beta0,  : 
  Mat::head_cols(): size out of bounds

Data: data.rds.zip

I would greatly appreciate your help.

michaeldgarber commented 4 years ago

Hi, @IdaHjermitslev . I also had this issue. Depending on the covariates, it tended to occur with covariates in my model, but not without them.

I wanted to control for covariates. I found the error never appeared when I added the following argument to my gsynth function call: EM = TRUE,

So perhaps see if this works?

out <- gsynth(Y ~ D + X1 + X2, data = data, index = c("id", "time"), 
              force = "two-way", EM = TRUE, CV = TRUE, r = c(0, 5), se = TRUE, inference = "parametric", 
              nboots = 1000, parallel = FALSE)
IdaHjermitslev commented 4 years ago

Dear @michaeldgarber. Yes, that resolved my issue. Thank you so much! Any idea why my particular data needs the Expectation Maximisation algorithm?

michaeldgarber commented 4 years ago

Great! No, I'm not sure why, unfortunately, so perhaps it can be left open with this as a noted workaround...