xuyiqing / gsynth

Generalized Synthetic Control Method
Other
131 stars 40 forks source link

gsynth fails with "'data' must be of a vector type, was 'NULL''"? when se=TRUE, works otherwise #56

Closed simenfuglestad closed 3 years ago

simenfuglestad commented 3 years ago

I have a data frame vdem5 with columns country, year, corruption, bnp and eu (the dichotomous treatment variable). I have tried using gsynth like this:

system.time(out <- gsynth(corruption ~ eu + democracy + bnp, data = vdem5, index = c("country","year"), force = "two-way", CV = TRUE, r= c(0,5), se = TRUE, inference = "parametric", nboots = 1000, parallel = FALSE))

Console output looks like this:

_Cross-validating ... r = 0; sigma2 = 0.00244; IC = -5.93214; MSPE = 0.00582 r = 1; sigma2 = 0.00071; IC = -6.05075; MSPE = 0.00289 r = 2; sigma2 = 0.00033; IC = -5.78892; MSPE = 0.00255 r = 3; sigma2 = 0.00011; IC = -5.95324; MSPE = 0.00242 r = 4; sigma2 = 0.00000; IC = -69.55168; MSPE = 0.00225* r = 5; sigma2 = -0.00000; IC = NaN; MSPE = Inf

r* = 4

Simulating errors ...Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : 'data' must be of a vector type, was 'NULL'_

I have checked multiple times that vdem5 is not NULL and that all the columns have no missing data.

However, if I set se=FALSE it works:

system.time(out <- gsynth(corruption ~ eu + democracy + bnp, data = vdem5, index = c("country","year"), force = "two-way", CV = TRUE, r= c(0,5), se = false, inference = "parametric", nboots = 1000, parallel = FALSE))

Now it runs through just fine. Any idea why se=TRUE causes it to fail?

liulch commented 3 years ago

Hi, I think that the error occurs on bootstrapped samples. Can you send us a dataset that only includes the id, time and treatment variables so we can try replicating the error? Thx!

simenfuglestad commented 3 years ago

Hi again, and sorry for the late reply.

Here is a google drive link containing the exact rdata file I've used, if you prefer I send it to you by other means then please let me know.

Also, for what it's worth, adding more countries(units, but not increasing the time scope) seemed to resolve the issue.

liulch commented 3 years ago

Thank you for the data. Will check it and reply to you.

liulch commented 3 years ago

Hi @simenfuglestad, have you tried the GitHub version? I tried your data and didn't get this error...

Screen Shot 2021-04-02 at 10 14 41 AM
simenfuglestad commented 3 years ago

Hello again,

That is odd, though I did install gsynth directly in R studio with install.packages("gsynth"). Do you suspect this to be the cause?

I tested it again with your exact code on the same dataset as well as a few variations, still get the same result. See the screenshots below.

2 1

liulch commented 3 years ago

Ah, that's the problem! you installed from cran, which is an older version. You can try installing from GitHub by typing devtools::install_github('xuyiqing/gsynth'). Hope it will help!

simenfuglestad commented 3 years ago

So I completetly uninstalled the CRAN version of gsynth, reinstalled via devtools like you said and now it works like a charm. Thank you very much for alll your help!

svknair commented 3 years ago

Hello,

I have been facing a similar issue raised above but the error message looks slightly different as shown below.

gsynth error1

I installed gsynth in RStudio. Based on suggestion above, I tried to install from GitHub but that has not worked. I tried to fix the problem using suggestions from this SO link but to no avail. I have installed gfortran and clang4 R Binaries from the links provided in the gsynth GitHub homepage. But the installation from GitHub just doesn't work. I get the following error message:

gsynth error2

Any suggestions how to fix this problem?

xuyiqing commented 3 years ago

Hi, are you installing from BigSur? If yes, please check out this file: https://yiqingxu.org/public/BigSurError.pdf

On Thu, Aug 5, 2021 at 5:02 PM svknair @.***> wrote:

Hello,

I have been facing a similar issue raised above but the error message looks slightly different as shown below.

[image: gsynth error1] https://user-images.githubusercontent.com/25752273/128436213-418d188c-efad-42ac-ad60-a051a3dd8c28.png

I installed synth in RStudio. Based on suggestion above, I tried to install from GitHub but that has not worked. I tried to fix the problem using suggestions from this SO link https://stackoverflow.com/questions/66359031/install-with-devtoolsinstall-github-fails-to-detect-build-tools but to no avail. I have installed gfortran and clang4 R Binaries from the links provided in the gsynth GitHub homepage. But the installation from GitHub just doesn't work. I get the following error message:

[image: gsynth error2] https://user-images.githubusercontent.com/25752273/128436234-2c04d023-55a4-4d96-aba0-e095cfb05f24.png

Any suggestions how to fix this problem?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/xuyiqing/gsynth/issues/56#issuecomment-893902848, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PKGAGIKD4Y6VCHD2GDELT3MRATANCNFSM4YVFJHPA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

svknair commented 3 years ago

Hi, are you installing from BigSur? If yes, please check out this file: https://yiqingxu.org/public/BigSurError.pdf

Yes, I am installing from BigSur 11.4. Thanks for sharing the solution. I will try that and let you know how it goes.

xuyiqing commented 3 years ago

Thank you, and it was really painstaking... I hope that R will release a new version of Rtools to address this...

On Thu, Aug 5, 2021 at 5:23 PM svknair @.***> wrote:

Hi, are you installing from BigSur? If yes, please check out this file: https://yiqingxu.org/public/BigSurError.pdf … <#m6666690129853809312>

Yes, I am installing from BigSur 11.4. Thanks for sharing the solution. I will try that and let you know how it goes.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/xuyiqing/gsynth/issues/56#issuecomment-893912045, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PKGDIKTMDUCEFI3VI62LT3MTRNANCNFSM4YVFJHPA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

-- Yiqing Xu

Assistant Professor Department of Political Science University of California, San Diego http://yiqingxu.org/

svknair commented 3 years ago

I think I kind of lost my way after step 3. The problem is not solved. Here is what I did after step 3:

I did not have a .profile file, so I created a text file with that name and copied the following:

export PATH="/usr/local/gfortran/bin:/Library/Frameworks/R.framework/Resources:$PATH"

After that, checking for gcc version didn't work. So I typed sudo nano /etc/paths in terminal and added /usr/local/gfortran/bin at the beginning of the file. Then I completed step 4.2 by creating the .Renviron file.

For step 5, I didn't have a Makevars file, so I created it and pasted the following:

`FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin20/20.5.0 -L/usr/local/gfortran/lib

CC = gcc CXX = g++ CXX98 = g++ CXX11 = g++ CXX14 = g++ CXX17 = g++ CXX20 = g++ CXXCPP = g++ FC = gfortran F77 = gfortran OBJC = gcc OBJCXX = g++`

After all this I tried installing gsynth from GitHub and got the same error message as before. Not sure if I am doing anything wrong while trying to implement your solution.

xuyiqing commented 3 years ago

Hi,

I can't debug your system setup. I'll try to update the CRAN version such that you'll be able to install the package from it using binaries. It may take a few days (apologies).

Best, Yiqng

On Thu, Aug 5, 2021 at 9:47 PM svknair @.***> wrote:

I think I kind of lost my way after step 3. The problem is not solved. Here is what I did after step 3:

I did not have a .profile file, so I created a text file with that name and copied the following:

export PATH="/usr/local/gfortran/bin:/Library/Frameworks/R.framework/Resources:$PATH"

After that, checking for gcc version didn't work. So I typed sudo nano /etc/paths in terminal and added /usr/local/gfortran/bin at the beginning of the file. Then I completed step 4.2 by creating the .Renviron file.

For step 5, I didn't have a Makevars file, so I created it and pasted the following:

`FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin20/20.5.0 -L/usr/local/gfortran/lib

CC = gcc CXX = g++ CXX98 = g++ CXX11 = g++ CXX14 = g++ CXX17 = g++ CXX20 = g++ CXXCPP = g++ FC = gfortran F77 = gfortran OBJC = gcc OBJCXX = g++`

After all this I tried installing gsynth from GitHub and got the same error message as before. Not sure if I am doing anything wrong while trying to implement your solution.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/xuyiqing/gsynth/issues/56#issuecomment-893997775, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PKGBPKDQOV2BYAEAOLNDT3NSOJANCNFSM4YVFJHPA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

-- Yiqing Xu

Assistant Professor Department of Political Science University of California, San Diego http://yiqingxu.org/

svknair commented 3 years ago

Hi,

Appreciate your time and help.

Thanks

xuyiqing commented 3 years ago

A new version (1.2.1) is shipped to CRAN. It will take a few days for CRAN to release a binary version of the package, which does not require compilation.

On Thu, Aug 5, 2021 at 10:23 PM svknair @.***> wrote:

Hi,

Appreciate your time and help.

Thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/xuyiqing/gsynth/issues/56#issuecomment-894009999, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PKGE7VDWPRCXOYGX642DT3NWWRANCNFSM4YVFJHPA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

-- Yiqing Xu

Assistant Professor Department of Political Science University of California, San Diego http://yiqingxu.org/

xuyiqing commented 3 years ago

You can also try installing from this binary build https://github.com/xuyiqing/gsynth/releases/download/1.2.1/gsynth_1.2.1.tgz that I just released on Github: RStudio -> Tool -> Install Packages -> From File

On Fri, Aug 6, 2021 at 7:58 AM Yiqing Xu @.***> wrote:

A new version (1.2.1) is shipped to CRAN. It will take a few days for CRAN to release a binary version of the package, which does not require compilation.

On Thu, Aug 5, 2021 at 10:23 PM svknair @.***> wrote:

Hi,

Appreciate your time and help.

Thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/xuyiqing/gsynth/issues/56#issuecomment-894009999, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PKGE7VDWPRCXOYGX642DT3NWWRANCNFSM4YVFJHPA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

-- Yiqing Xu

Assistant Professor Department of Political Science University of California, San Diego http://yiqingxu.org/

-- Yiqing Xu

Assistant Professor Department of Political Science University of California, San Diego http://yiqingxu.org/

svknair commented 3 years ago

I downloaded the latest version (1.2.1) from CRAN. But R aborts while running gsynth. I tried running gsynth after setting se = FALSE and got the following error:

Error in data_ub_adj(data_I, data_ub) : function 'Rcpp_precious_remove' not provided by package 'Rcpp'

Do you think this is still related to the macOS problem?

xuyiqing commented 3 years ago

Have you installed Rcpp?

On Sun, Aug 8, 2021 at 8:34 PM svknair @.***> wrote:

I downloaded the latest version (1.2.1) from CRAN. But R aborts while running gsynth. I tried running gsynth after setting se = FALSE and got the following error:

Error in data_ub_adj(data_I, data_ub) : function 'Rcpp_precious_remove' not provided by package 'Rcpp'

Do you think this is still related to the macOS problem?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/xuyiqing/gsynth/issues/56#issuecomment-894929300, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PKGFBFZJMIIILBA6HBT3T35EDZANCNFSM4YVFJHPA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

-- Yiqing Xu

Assistant Professor Department of Political Science University of California, San Diego http://yiqingxu.org/

svknair commented 3 years ago

Yes, I have installed Rcpp. I actually updated Rcpp package to the latest version and now gsynth works fine. Thanks much for your help!