xuyiqing / gsynth

Generalized Synthetic Control Method
Other
132 stars 40 forks source link

trying to set rownames for vector #22

Open bjorn81 opened 5 years ago

bjorn81 commented 5 years ago

This is where it breaks, line 531 in the main function:

if (!is.null(out$alpha.tr)) { rownames(out$alpha.tr) <- iname[which(out$tr == 1)] colnames(out$alpha.tr) <- "" }

I'm not sure whether out$alpha.tr should always be a matrix, but it seems to be either a vector or a matrix depending on the if statement here in synth.core

if (max(T0) == T0.min & (!0 %in% I.tr)) { alpha.tr.lv <- colMeans(U.lv) U.tr <- U.tr - matrix(alpha.tr.lv, TT, Ntr, byrow = TRUE) } else { alpha.tr.lv <- sapply(U.lv, mean) U.tr <- U.tr - matrix(alpha.tr.lv, TT, Ntr, byrow = TRUE) } I'm not into the details of the package or the method enough to be more helpful than this.

liulch commented 5 years ago

Thanks for your comment. I remember that I have fixed this bug in this version? In a earlier version of gsynth, out$alpha.tr is a vector when the model contains no factors. And in the current version, it will be converted to a matrix object in the final part of the main function. Have you updated the package?

bjorn81 commented 5 years ago

I'm using package version 1.09, which seems to be the latest one on github. Perhaps there are some exceptions where the conversion to a matrix does not take place? Where the code would break for me, out$alpha.tr was a seemingly valid vector with decimal numbers, only it could not be supplied with row names, being a vector.

bjorn81 commented 5 years ago

It seems like all that's needed is to wrap alpha.tr.lv <- colMeans(U.lv) with as.matrix()

bjorn81 commented 5 years ago

Indeed this issue has been fixed on the git version. But in the cran version the if-clause that makes sure alpha.tr is a matrix is missing:

`
if (!is.null(out$alpha.tr)) {

    if (class(out$alpha.tr) == "numeric") { #missing

        out$alpha.tr <- as.matrix(out$alpha.tr) #missing

    } #missing

    rownames(out$alpha.tr) <- iname[which(out$tr == 1)]

    colnames(out$alpha.tr) <- ""

}

`

Sorry I'm not able to do a better job at formatting the text above.

xuyiqing commented 5 years ago

Thank you.

On Fri, Nov 23, 2018, 01:30 bjorn81 <notifications@github.com wrote:

Indeed this issue has been fixed on the git version. But in the cran version the if-clause that makes sure alpha.tr is a matrix is missing:

if (!is.null(out$alpha.tr)) { if (class(out$alpha.tr) == "numeric") { out$alpha.tr <- as.matrix(out$alpha.tr) } rownames(out$alpha.tr) <- iname[which(out$tr == 1)] colnames(out$alpha.tr) <- "" }

— 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/22#issuecomment-441191460, or mute the thread https://github.com/notifications/unsubscribe-auth/AHT1GEvRtXiO7r5Aic1beljc389Z6T3fks5ux8BAgaJpZM4Ypnn5 .