Skip to content

Commit

Permalink
version 1.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
liulch committed May 15, 2020
1 parent e631f0f commit 3beb4c6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 83 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: gsynth
Type: Package
Title: Generalized Synthetic Control Method
Version: 1.1.6
Date: 2020-03-06
Date: 2020-05-15
Author: Yiqing Xu, Licheng Liu
Maintainer: Yiqing Xu <yiqingxu@ucsd.edu>
Description: Provides causal inference with interactive fixed-effect models. It imputes counterfactuals for each treated unit using control group information based on a linear interactive fixed effects model that incorporates unit-specific intercepts interacted with time-varying coefficients. This method generalizes the synthetic control method to the case of multiple treated units and variable treatment periods, and improves efficiency and interpretability. This version supports unbalanced panels and implements the matrix completion method. Main reference: Yiqing Xu (2017) <doi:10.1017/pan.2016.2>.
Expand Down
9 changes: 6 additions & 3 deletions R/core.R
Original file line number Diff line number Diff line change
Expand Up @@ -2798,9 +2798,12 @@ synth.boot<-function(Y,
cat("\r")
}

eff.na.sum <- sapply(1:nboots, function(vec){sum(is.na(c(eff.boot[,,vec])))})
eff.na.count <- sum(eff.na.sum == TT * Ntr)
if (eff.na.count == nboots) {
##cat(nboots)

##eff.na.sum <- sapply(1:nboots, function(vec){sum(is.na(c(eff.boot[,,vec])))})
##eff.na.count <- sum(eff.na.sum == TT * Ntr)
eff.na.sum <- sum(is.na(c(att.avg.boot)))
if (eff.na.sum == nboots) {
stop("Bootstrap inference fails. Please check the data.\n")
}

Expand Down
5 changes: 5 additions & 0 deletions R/default.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ gsynth.default <- function(formula = NULL,data, # a data frame (long-form)
stop("\"inference\" option misspecified; choose from c(\"parametric\", \"nonparametric\", \"jackknife\").")
}

if (inference == "parametric" && !is.null(cl)) {
cl <- NULL
cat("\nFor clustered bootsrap, please use the nonparametric procedure.\n")
}

## nboots
if (se == TRUE & nboots <= 0) {
stop("\"nboots\" option misspecified. Try, for example, nboots = 200.")
Expand Down
89 changes: 12 additions & 77 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ plot.gsynth <- function(x,
axis.adjust = FALSE,
theme.bw = FALSE,
shade.post = NULL,
legend.labs = NULL,
...){


Expand Down Expand Up @@ -366,15 +365,9 @@ plot.gsynth <- function(x,

## legend
set.limits = c("tr","tr.pst","co")
set.labels = c("Treated (Pre)", "Treated (Post)","Controls")
if (is.null(legend.labs)!=TRUE) {
if (length(set.labels)!=length(legend.labs)) {
stop("Wrong vector length in \"legend.labs\".")
} else {
set.labels <- as.character(legend.labs)
}
}

set.labels = c("Treated (Pre)",
"Treated (Post)",
"Controls")
if (theme.bw == FALSE) {
set.colors = c("#FC8D6280","red","#99999950")
} else {
Expand Down Expand Up @@ -576,13 +569,6 @@ plot.gsynth <- function(x,
## legend
set.limits = c("tr","ct")
set.labels = c("Treated", "Estimated Y(0)")
if (is.null(legend.labs)!=TRUE) {
if (length(set.labels)!=length(legend.labs)) {
stop("Wrong vector length in \"legend.labs\".")
} else {
set.labels <- as.character(legend.labs)
}
}
set.colors = c("black","steelblue")
set.linetypes = c("solid","longdash")
set.linewidth = rep(line.width[1],2)
Expand Down Expand Up @@ -649,14 +635,8 @@ plot.gsynth <- function(x,
alpha = 0.15, fill = "steelblue")

set.limits = c("tr","co.band","ct")
set.labels = c("Treated", "Controls (5-95% Quantiles)","Estimated Y(0)")
if (is.null(legend.labs)!=TRUE) {
if (length(set.labels)!=length(legend.labs)) {
stop("Wrong vector length in \"legend.labs\".")
} else {
set.labels <- as.character(legend.labs)
}
}
set.labels = c("Treated", "Controls (5-95% Quantiles)",
"Estimated Y(0)")
set.colors = c("black","#4682B480","steelblue")
set.linetypes = c("solid","solid","longdash")
set.linewidth = c(line.width[1],4,line.width[1])
Expand Down Expand Up @@ -720,13 +700,6 @@ plot.gsynth <- function(x,
## legend
set.limits = c("tr","raw.co","ct")
set.labels = c("Treated","Controls","Estimated Y(0)")
if (is.null(legend.labs)!=TRUE) {
if (length(set.labels)!=length(legend.labs)) {
stop("Wrong vector length in \"legend.labs\".")
} else {
set.labels <- as.character(legend.labs)
}
}
set.colors = c("black","#4682B420","steelblue")
set.linetypes = c("solid","solid","longdash")
set.linewidth = c(line.width[1],line.width[2],line.width[1])
Expand Down Expand Up @@ -785,14 +758,8 @@ plot.gsynth <- function(x,

## legend
set.limits = c("tr","co")
set.labels = c("Treated Average", "Estimated Y(0) Average")
if (is.null(legend.labs)!=TRUE) {
if (length(set.labels)!=length(legend.labs)) {
stop("Wrong vector length in \"legend.labs\".")
} else {
set.labels <- as.character(legend.labs)
}
}
set.labels = c("Treated Average",
"Estimated Y(0) Average")
set.colors = c("black","steelblue")
set.linetypes = c("solid","longdash")
set.linewidth = rep(line.width[1],2)
Expand Down Expand Up @@ -864,13 +831,6 @@ plot.gsynth <- function(x,
"Estimated Y(0) Average",
"Treated 5-95% Quantiles",
"Controls 5-95% Quantiles")
if (is.null(legend.labs)!=TRUE) {
if (length(set.labels)!=length(legend.labs)) {
stop("Wrong vector length in \"legend.labs\".")
} else {
set.labels <- as.character(legend.labs)
}
}
set.colors = c("black","steelblue","#77777750","#4682B480")
set.linetypes = c("solid","longdash","solid","solid")
set.linewidth = c(rep(line.width[1],2),4,4)
Expand Down Expand Up @@ -938,13 +898,6 @@ plot.gsynth <- function(x,
"Estimated Y(0) Average",
"Treated Raw Data",
"Controls Raw Data")
if (is.null(legend.labs)!=TRUE) {
if (length(set.labels)!=length(legend.labs)) {
stop("Wrong vector length in \"legend.labs\".")
} else {
set.labels <- as.character(legend.labs)
}
}
set.colors = c("black","steelblue","#77777750","#4682B420")
set.linetypes = c("solid","longdash","solid","solid")
set.linewidth = rep(line.width,each=2)
Expand Down Expand Up @@ -1045,14 +998,8 @@ plot.gsynth <- function(x,

## legend
set.limits = c("tr","co")
set.labels = c("Treated Average", "Estimated Y(0) Average")
if (is.null(legend.labs)!=TRUE) {
if (length(set.labels)!=length(legend.labs)) {
stop("Wrong vector length in \"legend.labs\".")
} else {
set.labels <- as.character(legend.labs)
}
}
set.labels = c("Treated Average",
"Estimated Y(0) Average")
set.colors = c("black","steelblue")
set.linetypes = c("solid","longdash")
set.linewidth = rep(line.width[1],2)
Expand Down Expand Up @@ -1117,14 +1064,9 @@ plot.gsynth <- function(x,
alpha = 0.15, fill = "red")

set.limits = c("tr","co","tr.band")
set.labels = c("Treated Average", "Estimated Y(0) Average","Treated 5-95% Quantiles")
if (is.null(legend.labs)!=TRUE) {
if (length(set.labels)!=length(legend.labs)) {
stop("Wrong vector length in \"legend.labs\".")
} else {
set.labels <- as.character(legend.labs)
}
}
set.labels = c("Treated Average",
"Estimated Y(0) Average",
"Treated 5-95% Quantiles")
set.colors = c("black","steelblue","#77777750")
set.linetypes = c("solid","longdash","solid")
set.linewidth = c(rep(line.width[1],2),4)
Expand Down Expand Up @@ -1189,13 +1131,6 @@ plot.gsynth <- function(x,
set.labels = c("Treated Average",
"Estimated Y(0) Average",
"Treated Raw Data")
if (is.null(legend.labs)!=TRUE) {
if (length(set.labels)!=length(legend.labs)) {
stop("Wrong vector length in \"legend.labs\".")
} else {
set.labels <- as.character(legend.labs)
}
}
set.colors = c("black","steelblue","#77777750")
set.linetypes = c("solid","longdash","solid")
set.linewidth = c(rep(line.width[1],2),line.width[2])
Expand Down
3 changes: 1 addition & 2 deletions man/plot.gsynth.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
Useful when class of time variable is string and data magnitude is large.}
\item{theme.bw}{a logical flag indicating whether to use a black/white theme.}
\item{shade.post}{a logical flag controlling whether to shade the post-treatment periods.}
\item{legend.lab}{a string vector specifying labels shown in the legends.}
\item{\dots}{other argv.}
\item{\dots}{other argv.}
}
\details{
\code{plot.gsynth} visualizes the raw data used by, or estimation
Expand Down

0 comments on commit 3beb4c6

Please sign in to comment.