xuyiqing / fect

fixed effect counterfactual estimators
Other
57 stars 20 forks source link

misleading error message when r=0 and method=gsynth #43

Open MatthieuStigler opened 1 month ago

MatthieuStigler commented 1 month ago

I am facing an error when using fect(..., CV = TRUE, r = 0):

Cross validation cannot be performed since available pre-treatment records of treated units are too few. So set r.cv = 0.

But it seems this has nothing to do with the pre-treatment periods, but with how r is specified, since setting r = c(0, 5) will work with the same dataset?

Also, the help file says:

r: an integer specifying the number of factors. If CV = TRUE, the cross validation procedure will select the optimal number of factors from r to 5.

But it seems it is rather a range of integers with CV=TRUE?

Thanks!

reprex

library(fect)
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2

data(fect)

out_fect <- fect(Y ~ D + X1 + X2, data = simdata1, 
                 index = c("id","time"), force = "two-way", method="gsynth",
                 CV = TRUE, r = 0) 
#> Cross-validating ...
#> Criterion: Mean Squared Prediction Error
#> Interactive fixed effects model...
#> Cross validation cannot be performed since available pre-treatment records of treated units are too few. So set r.cv = 0.
#> 
out_fect <- fect(Y ~ D + X1 + X2, data = simdata1, 
                 index = c("id","time"), force = "two-way", method="gsynth",
                 CV = TRUE, r = c(0, 5)) 
#> Cross-validating ...
#> Criterion: Mean Squared Prediction Error
#> Interactive fixed effects model...
#> Cross-validating ...
#> 
#>  r = 0; sigma2 = 7.60975; IC = 2.34653; PC = 7.31406; MSPE = 8.91717
#> 
#>  r = 1; sigma2 = 4.52459; IC = 2.13439; PC = 5.15203; MSPE = 6.31714
#> 
#>  r = 2; sigma2 = 3.99766; IC = 2.31368; PC = 5.26402; MSPE = 4.81494
#> *
#> 
#>  r = 3; sigma2 = 3.86501; IC = 2.57837; PC = 5.77993; MSPE = 5.07864
#> 
#>  r = 4; sigma2 = 3.74818; IC = 2.84146; PC = 6.27705; MSPE = 5.33708
#> 
#>  r = 5; sigma2 = 3.63198; IC = 3.09908; PC = 6.73553; MSPE = 5.70602
#> 
#> 
#>  r* = 2
#> 

Created on 2024-10-15 with reprex v2.1.1