xuyiqing / gsynth

Generalized Synthetic Control Method
Other
131 stars 40 forks source link

Understanding EM algorithm in gsynth #47

Open yafs123 opened 3 years ago

yafs123 commented 3 years ago

Hi Yiqing,

Thanks for making such a fantastic package.

I am running an experiment with only 1 treated unit (N_tr = 1) and 38 units in the control group (N_co = 38). The dataset is unbalanced. I have completed the tutorial you have uploaded on your website. (http://yiqingxu.org/software/gsynth/gsynth_examples.html). It seems like "gsynth" can handle unbalanced panel dataset by using the EM algorithm. My question is related to the output of "gsynth". The output only shows NA values in the missing rows. To be precise, the algorithm did not estimate ATT where missing values exists. I thought that the EM algorithm would fill in missing values. You can find the example code below.

Best regards, Yafee

#####################

Code

#####################

library(gsynth) library(data.table)

Datasets

data(gsynth) names(turnout)

Set seed

set.seed(123456)

Remove rows

turnout.ub <- turnout[-c(which(turnout$abb=="WY")[1:15], sample(1:nrow(turnout),50,replace=FALSE)),]

Overview of missing values

panelView(turnout ~ policy_edr + policy_mail_in + policy_motor, data = turnout.ub, index = c("abb","year"), pre.post = TRUE)

Transform to data.table object

setDT(turnout.ub)

Remove all treated units without ID

turnout.ub <- turnout.ub[!(abb %in% c("CT","IA","ME","MN","MT","NH","WI","WY"))]

Run gsynth

out <- gsynth(turnout ~ policy_edr + policy_mail_in + policy_motor, data = turnout.ub,
index = c("abb","year"), se = TRUE, inference = "parametric", r = c(0, 5), CV = TRUE, force = "two-way", EM = TRUE, parallel = TRUE, min.T0 = 8, nboots = 1000, seed = 02139)

print results

out

xuyiqing commented 3 years ago

Licheng, could you look into it and explain to Yafee what's going on?

Dear Yafee, for your application, we actually have a better method https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3649226 that adopts the Bayesian approach. We plan to release the package on R very soon.

On Thu, Sep 24, 2020 at 12:40 AM yafs123 notifications@github.com wrote:

Hi Yiqing,

Thanks for making such a fantastic package.

I am running an experiment with only 1 treated unit (N_tr = 1) and 38 units in the control group (N_co = 38). The dataset is unbalanced. I have completed the tutorial you have uploaded on your website. ( http://yiqingxu.org/software/gsynth/gsynth_examples.html). It seems like "gsynth" can handle unbalanced panel dataset by using the EM algorithm. My question is related to the output of "gsynth". The output only shows NA values in the missing rows. To be precise, the algorithm did not estimate ATT where missing values exists. I thought that the EM algorithm would fill in missing values. You can find the example code below.

Best regards, Yafee

##################### Code

#####################

library(gsynth) library(data.table) Datasets

data(gsynth) names(turnout) Set seed

set.seed(123456) Remove rows

turnout.ub <- turnout[-c(which(turnout$abb=="WY")[1:15], sample(1:nrow(turnout),50,replace=FALSE)),] Overview of missing values

panelView(turnout ~ policy_edr + policy_mail_in + policy_motor, data = turnout.ub, index = c("abb","year"), pre.post = TRUE) Transform to data.table object

setDT(turnout.ub) Remove all treated units without ID

turnout.ub <- turnout.ub[!(abb %in% c("CT","IA","ME","MN","MT","NH","WI","WY"))] Run gsynth

out <- gsynth(turnout ~ policy_edr + policy_mail_in + policy_motor, data = turnout.ub, index = c("abb","year"), se = TRUE, inference = "parametric", r = c(0, 5), CV = TRUE, force = "two-way", EM = TRUE, parallel = TRUE, min.T0 = 8, nboots = 1000, seed = 02139) print results

out

— 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/47, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PKGFRERKA6K3X35JPEFTSHLZWZANCNFSM4RX6TT2Q .

-- Yiqing Xu

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