xuyiqing / gsynth

Generalized Synthetic Control Method
Other
134 stars 41 forks source link

Option `weight` triggers an error for staggered design #18

Open jjchern opened 6 years ago

jjchern commented 6 years ago

Below is a minimum example. First, load the turout data and add a weighting variable of all 1:

library(gsynth)
data(gsynth)
turnout$W = 1

The following code (without weight) work as expected:

out <- gsynth(turnout ~ policy_edr, data = turnout, EM = FALSE, MC = FALSE, 
  index = c("abb", "year"), se = FALSE)
#> Cross-validating ... 
#>  r = 0; sigma2 = 93.28854; IC = 4.53570; MSPE = 50.99510
#>  r = 1; sigma2 = 33.21362; IC = 3.95883; MSPE = 47.57511
#>  r = 2; sigma2 = 10.95689; IC = 3.29076; MSPE = 10.56376*
#>  r = 3; sigma2 = 7.92021; IC = 3.39219; MSPE = 12.33878
#>  r = 4; sigma2 = 5.74782; IC = 3.48262; MSPE = 14.87479
#>  r = 5; sigma2 = 4.16885; IC = 3.55753; MSPE = 16.83409
#> 
#>  r* = 2

Allowing weight yields an error about a missing object: object 'Y.tr.cnt' not found:

out <- gsynth(turnout ~ policy_edr, data = turnout, weight = "W", EM = FALSE, 
  MC = FALSE, index = c("abb", "year"), se = FALSE)
#> Cross-validating ... 
#>  r = 0; sigma2 = 93.28854; IC = 4.53570; MSPE = 50.99510
#>  r = 1; sigma2 = 33.21362; IC = 3.95883; MSPE = 47.57511
#>  r = 2; sigma2 = 10.95689; IC = 3.29076; MSPE = 10.56376*
#>  r = 3; sigma2 = 7.92021; IC = 3.39219; MSPE = 12.33878
#>  r = 4; sigma2 = 5.74782; IC = 3.48262; MSPE = 14.87479
#>  r = 5; sigma2 = 4.16885; IC = 3.55753; MSPE = 16.83409
#> 
#>  r* = 2
#> Error in synth.core(Y = Y, X = X, D = D, I = I, W = W, r = r, r.end = r.end, : object 'Y.tr.cnt' not found

I got the same error if I turned on the EM or MC option. Will submit a PR soon to fix the issue.