xuyiqing / gsynth

Generalized Synthetic Control Method
Other
135 stars 41 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 5 years ago

IdaHjermitslev commented 5 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 5 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 5 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 5 years ago

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

pchest commented 1 month 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)

I experienced the same error code and EM = TRUE resolved it. Thanks for the tip!

xuyiqing commented 1 month ago

Hi could you try the "fect" package instead, and set

method = "gsynth"

We're in the process of merging these two package and will more actively maintain "fect".

Thanks!

On Wed, Sep 18, 2024 at 1:31 PM Patrick Chester @.***> wrote:

Hi, @IdaHjermitslev https://github.com/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)

I experienced the same error code and EM = TRUE resolved it. Thanks for the tip!

— Reply to this email directly, view it on GitHub https://github.com/xuyiqing/gsynth/issues/32#issuecomment-2359351025, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PKGAI6MABHHB32X55UJDZXHPLVAVCNFSM6AAAAABOOPO53OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJZGM2TCMBSGU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Yiqing Xu

Assistant Professor Department of Political Science Stanford University https://yiqingxu.org/

pchest commented 1 month ago

@xuyiqing Thanks for the feedback! I'll give fect a try.