nevertreated = T,
printdetails = F)
data.never <- (subset(data, data$year<2009))
data.never2 = data.never[data.never$cohort_year==2009, "cohort_year"] <- 0
CS_out_never_treated <- att_gt("dep_var", data = data.never2,
first.treat.name="cohort_year",
idname="unit", tname="year", aggte = T,
clustervars = "state",
bstrap=T, cband=T,
maxe = 6,
mine = -4,
nevertreated = T,
printdetails = F)
data.never <- (subset(data, data$year<2009))
data.never <- (subset(data, data$year<2009))
data.never2 = data.never
data.never2[data.never2$cohort_year==2009, "cohort_year"] <- 0
CS_out_never_treated <- att_gt("dep_var", data = data.never2,
first.treat.name="cohort_year",
idname="unit", tname="year", aggte = T,
clustervars = "state",
bstrap=T, cband=T,
maxe = 6,
mine = -4,
nevertreated = T,
printdetails = F)
CS_out_never_treated$att
AS.intFE$coefficients["c1985_tau0",] - CS_out_never_treated$att[6]
AS.intFE$coefficients["c1985_tau1",] - CS_out_never_treated$att[7]
AS.intFE$coefficients["c1985_tau2",] - CS_out_never_treated$att[8]
AS.intFE$coefficients
AS.intFE$coefficients["c1985_tau_m1",] - CS_out_never_treated$att[4]
CS_out_never_treated$att[4]
AS.intFE$coefficients["c1985_tau_m1",]
AS.intFE$coefficients["c1985_tau_m2",] - CS_out_never_treated$att[4]
AS.intFE$coefficients["c1985_tau_m5",] - CS_out_never_treated$att[1]
CS_out_never_treated$att
AS.intFE$coefficients["c1985_tau0",] - CS_out_never_treated$att[6]
AS.intFE$coefficients["c1991_tau0",] - CS_out_never_treated$att[41]
CS_out_never_treated$att
# First 6 lags for group 1985 - This is the ATT(g,t) for g=1985
AS.intFE$coefficients["c1985_tau0",] - CS_out_never_treated$att[6]
AS.intFE$coefficients["c1985_tau1",] - CS_out_never_treated$att[7]
AS.intFE$coefficients["c1985_tau2",] - CS_out_never_treated$att[8]
AS.intFE$coefficients["c1985_tau3",] - CS_out_never_treated$att[9]
AS.intFE$coefficients["c1985_tau4",] - CS_out_never_treated$att[10]
AS.intFE$coefficients["c1985_tau5",] - CS_out_never_treated$att[11]
# First 6 lags for group 1991 - This is the ATT(g,t) for g=1991
AS.intFE$coefficients["c1991_tau0",] - CS_out_never_treated$att[41]
AS.intFE$coefficients["c1991_tau1",] - CS_out_never_treated$att[42]
AS.intFE$coefficients["c1991_tau2",] - CS_out_never_treated$att[43]
AS.intFE$coefficients["c1991_tau3",] - CS_out_never_treated$att[44]
AS.intFE$coefficients["c1991_tau4",] - CS_out_never_treated$att[45]
AS.intFE$coefficients["c1991_tau5",] - CS_out_never_treated$att[46]
# First 6 lags for group 1997 -This is the ATT(g,t) for g=1997
AS.intFE$coefficients["c1997_tau0",] - CS_out_never_treated$att[76]
AS.intFE$coefficients["c1997_tau1",] - CS_out_never_treated$att[77]
AS.intFE$coefficients["c1997_tau2",] - CS_out_never_treated$att[78]
AS.intFE$coefficients["c1997_tau3",] - CS_out_never_treated$att[79]
AS.intFE$coefficients["c1997_tau4",] - CS_out_never_treated$att[80]
AS.intFE$coefficients["c1997_tau5",] - CS_out_never_treated$att[81]
# First 6 lags for group 2003 - This is the ATT(g,t) for g=2003
AS.intFE$coefficients["c2003_tau0",] - CS_out_never_treated$att[111]
AS.intFE$coefficients["c2003_tau1",] - CS_out_never_treated$att[112]
AS.intFE$coefficients["c2003_tau2",] - CS_out_never_treated$att[113]
AS.intFE$coefficients["c2003_tau3",] - CS_out_never_treated$att[114]
AS.intFE$coefficients["c2003_tau4",] - CS_out_never_treated$att[115]
AS.intFE$coefficients["c2003_tau5",] - CS_out_never_treated$att[116]
AS.intFE = lfe::felm(as.formula(paste("dep_var ~", #paste(colnames(ttau), collapse = " + "),
# "+",paste(colnames(c2009_ttau), collapse = " + "),
"+",paste(colnames(c2003_ttau), collapse = " + "),
"+",paste(colnames(c1997_ttau), collapse = " + "),
"+",paste(colnames(c1991_ttau), collapse = " + "),
"+",paste(colnames(c1985_ttau), collapse = " + "),
"| unit + year | 0 | state")),
data = data.never,
exactDOF = T)
summary(AS.intFE)
CS_out_never_treated$V
CS_out_never_treated$V[,116]
sqrt(CS_out_never_treated$V[,116])
summary(CS_out_never_treated)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau), collapse = " + "),
"| unit + year | 0 | state")),
data = data.never,
exactDOF = F)
#----------------------------------------------------------------------------
# Implement A&S method based on interacted FE regression model
#----------------------------------------------------------------------------
# Create the treatment leads and lag dummies
data.never <- data.never[order(-data.never$cohort_year, data.never$year),]
data.never$ttau <- data.never$year - data.never$cohort_year
ttau = fastDummies::dummy_cols(data.frame(ttau = data.never$ttau))
data.never <- (subset(data, data$year<2009))
data.never2 = data.never
data.never2[data.never2$cohort_year==2009, "cohort_year"] <- 0
CS_out_never_treated <- att_gt("dep_var", data = data.never2,
first.treat.name="cohort_year",
idname="unit", tname="year", aggte = T,
clustervars = "state",
bstrap=T, cband=T,
maxe = 6,
mine = -4,
nevertreated = T,
printdetails = F)
#----------------------------------------------------------------------------
# Implement A&S method based on interacted FE regression model
#----------------------------------------------------------------------------
# Create the treatment leads and lag dummies
data.never <- data.never[order(-data.never$cohort_year, data.never$year),]
data.never$ttau <- data.never$year - data.never$cohort_year
ttau = fastDummies::dummy_cols(data.frame(ttau = data.never$ttau))
# I drop the tau_NA, tau_-1 (baseline) and tau_-29.Dropping two periods avoid problems as pointed out by B&J.
ttau = ttau[, !(colnames(ttau) %in% c("ttau", "ttau_-1", "ttau_-29"))]
# I put _m instead of _- so the formula below doesn't collapse.
colnames(ttau)[1:27] <- paste0(rep("tau_m", 27),28:2)
cohort = fastDummies::dummy_cols(data.frame(cohort= data.never$cohort_year))[,-1]
c2009_ttau = cohort[,1] * ttau
c2003_ttau = cohort[,2] * ttau
c1997_ttau = cohort[,3] * ttau
c1991_ttau = cohort[,4] * ttau
c1985_ttau = cohort[,5] * ttau
colnames(c2009_ttau)[1:27] <- paste0(rep("c2009_tau_m", 27),28:2)
colnames(c2009_ttau)[28:51] <- paste0(rep("c2009_tau", 24),0:23)
colnames(c2003_ttau)[1:27] <- paste0(rep("c2003_tau_m", 27),28:2)
colnames(c2003_ttau)[28:51] <- paste0(rep("c2003_tau", 24),0:23)
colnames(c1997_ttau)[1:27] <- paste0(rep("c1997_tau_m", 27),28:2)
colnames(c1997_ttau)[28:51] <- paste0(rep("c1997_tau", 24),0:23)
colnames(c1991_ttau)[1:27] <- paste0(rep("c1991_tau_m", 27),28:2)
colnames(c1991_ttau)[28:51] <- paste0(rep("c1991_tau", 24),0:23)
colnames(c1985_ttau)[1:27] <- paste0(rep("c1985_tau_m", 27),28:2)
colnames(c1985_ttau)[28:51] <- paste0(rep("c1985_tau", 24),0:23)
data.never = cbind(data.never, ttau, c2009_ttau, c2003_ttau, c1997_ttau, c1991_ttau, c1985_ttau)
AS.intFE = lfe::felm(as.formula(paste("dep_var ~", #paste(colnames(ttau), collapse = " + "),
# "+",paste(colnames(c2009_ttau), collapse = " + "),
"+",paste(colnames(c2003_ttau), collapse = " + "),
"+",paste(colnames(c1997_ttau), collapse = " + "),
"+",paste(colnames(c1991_ttau), collapse = " + "),
"+",paste(colnames(c1985_ttau), collapse = " + "),
"| unit + year | 0 | state")),
data = data.never,
exactDOF = F)
# First 6 lags for group 1985 - This is the ATT(g,t) for g=1985
AS.intFE$coefficients["c1985_tau0",] - CS_out_never_treated$att[6]
AS.intFE$coefficients["c1985_tau1",] - CS_out_never_treated$att[7]
AS.intFE$coefficients["c1985_tau2",] - CS_out_never_treated$att[8]
AS.intFE$coefficients["c1985_tau3",] - CS_out_never_treated$att[9]
AS.intFE$coefficients["c1985_tau4",] - CS_out_never_treated$att[10]
AS.intFE$coefficients["c1985_tau5",] - CS_out_never_treated$att[11]
# First 6 lags for group 1991 - This is the ATT(g,t) for g=1991
AS.intFE$coefficients["c1991_tau0",] - CS_out_never_treated$att[41]
AS.intFE$coefficients["c1991_tau1",] - CS_out_never_treated$att[42]
AS.intFE$coefficients["c1991_tau2",] - CS_out_never_treated$att[43]
AS.intFE$coefficients["c1991_tau3",] - CS_out_never_treated$att[44]
AS.intFE$coefficients["c1991_tau4",] - CS_out_never_treated$att[45]
AS.intFE$coefficients["c1991_tau5",] - CS_out_never_treated$att[46]
# First 6 lags for group 1997 -This is the ATT(g,t) for g=1997
AS.intFE$coefficients["c1997_tau0",] - CS_out_never_treated$att[76]
AS.intFE$coefficients["c1997_tau1",] - CS_out_never_treated$att[77]
AS.intFE$coefficients["c1997_tau2",] - CS_out_never_treated$att[78]
AS.intFE$coefficients["c1997_tau3",] - CS_out_never_treated$att[79]
AS.intFE$coefficients["c1997_tau4",] - CS_out_never_treated$att[80]
AS.intFE$coefficients["c1997_tau5",] - CS_out_never_treated$att[81]
# First 6 lags for group 2003 - This is the ATT(g,t) for g=2003
AS.intFE$coefficients["c2003_tau0",] - CS_out_never_treated$att[111]
AS.intFE$coefficients["c2003_tau1",] - CS_out_never_treated$att[112]
AS.intFE$coefficients["c2003_tau2",] - CS_out_never_treated$att[113]
AS.intFE$coefficients["c2003_tau3",] - CS_out_never_treated$att[114]
AS.intFE$coefficients["c2003_tau4",] - CS_out_never_treated$att[115]
AS.intFE$coefficients["c2003_tau5",] - CS_out_never_treated$att[116]
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau), collapse = " + "),
"| unit + year | 0 | state")),
data = data.never,
exactDOF = F)
summary(twfe.dyn)
colnames(ttau)
colnames(ttau)[-c(1:8)]
colnames(ttau)[-c(1:8, 48:51)]
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:8, 48:51)], collapse = " + "),
"| unit + year | 0 | state")),
data = data.never,
exactDOF = F)
summary(twfe.dyn)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:8)], collapse = " + "),
"| unit + year | 0 | state")),
data = data.never,
exactDOF = F)
summary(twfe.dyn)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:2)], collapse = " + "),
"| unit + year | 0 | state")),
data = data.never,
exactDOF = F)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:3)], collapse = " + "),
"| unit + year | 0 | state")),
data = data.never,
exactDOF = F)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:4)], collapse = " + "),
"| unit + year | 0 | state")),
data = data.never,
exactDOF = F)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:5)], collapse = " + "),
"| unit + year | 0 | state")),
data = data.never,
exactDOF = F)
summary(twfe.dyn)
data.twfe = cbind(data, ttau)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:5)], collapse = " + "),
"| unit + year | 0 | state")),
data = data.twfe,
exactDOF = F)
data.twfe = cbind(data, ttau)
ttau
# Create the treatment leads and lag dummies
data2 <- data[order(-data$cohort_year, data$year),]
data2$ttau <- data2$year - data2$cohort_year
ttau = fastDummies::dummy_cols(data.frame(ttau = data2$ttau))
# I drop the tau_NA, tau_-1 (baseline) and tau_-29.Dropping two periods avoid problems as pointed out by B&J.
ttau = ttau[, !(colnames(ttau) %in% c("ttau", "ttau_-1", "ttau_-29"))]
# I put _m instead of _- so the formula below doesn't collapse.
colnames(ttau)[1:27] <- paste0(rep("tau_m", 27),28:2)
data2 = cbind(data2, ttau)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:5)], collapse = " + "),
"| unit + year | 0 | state")),
data = data2,
exactDOF = F)
summary(twfe.dyn)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:2)], collapse = " + "),
"| unit + year | 0 | state")),
data = data2,
exactDOF = F)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:4)], collapse = " + "),
"| unit + year | 0 | state")),
data = data2,
exactDOF = F)
summary(twfe.dyn)
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau)[-c(1:5)], collapse = " + "),
"| unit + year | 0 | state")),
data = data2,
exactDOF = F)
twfe.dyn
summary(twfe.dyn)
#paste(colnames(ttau)[-c(1:5)]
twfe.dyn = lfe::felm(as.formula(paste("dep_var ~", paste(colnames(ttau), collapse = " + "),
"| unit + year | 0 | state")),
data = data2,
exactDOF = F)
summary(twfe.dyn)
library(tidyverse)
library(here)
library(lfe)
library(broom)
library(lubridate)
library(multcomp)
library(did)
library(did2)
library(ggthemes)
theme_set(theme_clean() + theme(plot.background = element_blank()))
select <- dplyr::select
filter <- dplyr::filter
# load the data
data <- read_rds(here::here("Data", "test_PP.rds"))
# load the data
data <- read_rds(here::here("test_PP.rds"))
data <- read_rds(here::here("test_PP.rds"))
devtools::install_github("tidyverse/rlang", force = T)
library(tidyverse)
library(here)
library(lfe)
library(broom)
library(lubridate)
library(multcomp)
library(did)
library(did2)
library(ggthemes)
theme_set(theme_clean() + theme(plot.background = element_blank()))
select <- dplyr::select
filter <- dplyr::filter
# load the data
data <- read_rds(here::here("test_PP.rds"))
# short covariates
cov1 <- c("size", "age", "size2", "age2")
install.packages(c("AER", "arules", "assertive.code", "assertive.data", "assertive.data.uk", "assertive.data.us", "assertive.matrices", "assertive.models", "backports", "bacondecomp", "bayesplot", "BB", "bdsmatrix", "bench", "benchmarkme", "benchmarkmeData", "BH", "bibtex", "bit", "blob", "BMA", "broom", "callr", "car", "carData", "caTools", "CBPS", "CDM", "checkmate", "classInt", "cli", "clipr", "cobalt", "coda", "commonmark", "covr", "cowplot", "cplexAPI", "cubature", "curl", "data.table", "DBI", "ddalpha", "Deriv", "devtools", "DiceDesign", "did", "digest", "dimRed", "doRNG", "doSNOW", "DRR", "DT", "dtplyr", "e1071", "enc", "energy", "evaluate", "expss", "fansi", "fastDummies", "fda", "fda.usc", "FNN", "forcats", "foreach", "formatR", "fs", "future", "gbm", "geometry", "ggpubr", "ggrepel", "ggridges", "ggsignif", "ggstance", "gh", "git2r", "glmnet", "globals", "gmm", "gmp", "goffda", "gower", "GPfit", "gplots", "hardhat", "Hmisc", "htmlTable", "htmltools", "htmlwidgets", "httpuv", "hunspell", "igraph", "ipred", "ISOcodes", "jomo", "jpeg", "jsonlite", "kernlab", "klaR", "knitr", "ks", "labelled", "Lahman", "later", "latticeExtra", "lava", "lavaan", "leaps", "lfe", "lhs", "lifecycle", "listenv", "lmtest", "loo", "magic", "manipulateWidget", "maptools", "markdown", "Matching", "matlib", "matrixStats", "maxLik", "mclust", "mice", "miceadds", "microbenchmark", "mime", "mirt", "miscTools", "mitml", "mitools", "mlogit", "mnlogit", "mnormt", "mockery", "modelr", "mpoly", "multcomp", "multicool", "mvtnorm", "nloptr", "NLP", "np", "numDeriv", "nycflights13", "openssl", "openxlsx", "optextras", "optimParallel", "optimx", "ordinal", "packrat", "pacman", "parsnip", "partitions", "pbapply", "pbkrtest", "permute", "pkgbuild", "pkgconfig", "pkgmaker", "plm", "pls", "plyr", "polycor", "pracma", "prediction", "prettyunits", "pROC", "processx", "prodlim", "progress", "promises", "ps", "qte", "quadprog", "quantreg", "questionr", "R.matlab", "R.methodsS3", "R.oo", "R.utils", "R6", "rcmdcheck", "Rcpp", "RcppArmadillo", "RcppEigen", "RcppGSL", "RCurl", "recipes", "registry", "rematch2", "remotes", "repurrrsive", "reshape", "Rfast", "rgl", "rJava", "RJSONIO", "rlang", "rlecuyer", "rmarkdown", "rmutil", "RMySQL", "rngtools", "robustbase", "roxygen2", "rrcov", "rsconnect", "RSQLite", "rstan", "rstanarm", "rstantools", "rstudioapi", "sandwich", "scales", "seewave", "selectr", "sfsmisc", "shiny", "shinyjs", "shinythemes", "sirt", "sjlabelled", "slam", "snakecase", "SnowballC", "sp", "SparseM", "spData", "spelling", "SQUAREM", "StanHeaders", "statmod", "stopwords", "stringi", "styler", "survey", "sys", "TAM", "testthat", "TH.data", "threejs", "tidypredict", "tidyr", "tidyselect", "tidytext", "tinytex", "tm", "trust", "twang", "usethis", "vegan", "webshot", "WeightIt", "whisker", "wordcloud", "xfun", "xlsx", "xtable", "xts", "yaml", "yardstick", "zip", "zoo"))
install.packages("vctrs")
install.packages(c("covr", "cplexAPI", "fs", "plyr", "tidytext"))
install.packages("tidytext")
install.packages("rlang")
install.packages("tidytext")
install.packages("tidytext")
install.packages("ggplot2")
(!identical(system.file(package="RevoUtils"), ""))
(!identical(system.file(package="RevoScaleR"), ""))
RevoUtils:::makeRevoVersion()
RevoUtils:::isMicrosoftRClient()
(!identical(system.file(package="RevoScaleR") , ""))
if (!identical(system.file(package="RevoScaleR") , "")){
options(defaultPackages=c(getOption("defaultPackages"), "rpart", "lattice", "RevoScaleR",
if(!identical(system.file(package="mrsdeploy"), "") && identical(.Platform$OS, "windows") && !identical(Sys.getenv("MRS_IN_DATABASE_HOST_PLATFORM"), "1")) "mrsdeploy",
# we have MicrosoftML package
if(!identical(system.file(package="MicrosoftML"),"") && isMMLSupported) "MicrosoftML",
"RevoMods", "RevoUtils", "RevoUtilsMath"))
if (nchar(hostName <- Sys.getenv("REVOHADOOPHOST")) && nchar(portNumber <- Sys.getenv("REVOHADOOPPORT")))
{
RevoScaleR::rxHdfsConnect(hostName=hostName, portNumber=as.numeric(portNumber))
}
} else {
options(defaultPackages=c(getOption("defaultPackages"), "RevoUtils"))
}
c(1,2,3)
a = c(1,2,3)
t(a)
a
library(devtools)
devtools::install_github("pedrohcgs/pstest")
#---------------------------------------------------
#      Standard and Stabalized-weighted ATT of DID
#      Panel Data case
#      All DID estimators
#
# Simulations based on R 3.6.2
# Updated: 01/20/2020
#---------------------------------------------------
#-----------------------------------------------------------------------------
# Startup - clear memory, load packages, and set parameters
# Clear memory
rm(list=ls())
#-----------------------------------------------------------------------------
# Basic parameters for the simulation - Doesn't change over setups
#nrep    <- 1000        # Monte Carlo replications
ncores  <- 14           # Number of cores to use in parallel
seed1   <- 1234         # Set initial seed (guaranteed reproducibility)
Xsi.ps <- .75           # pscore index (strength of common support)
nrep <- 10000           # Monte Carlo replications
#-----------------------------------------------------------------------------
# Set the Working Directory
address <- "C:/Users/santanph/Dropbox/Co-authored Projects/Doubly Robust DID/JoE/Second Round Revision/MonteCarlo"
setwd(address)
#-----------------------------------------------------------------------------
# load the necessary libraries
# Install DRDID package
devtools::install_github("pedrohcgs/DRDID", auth_token = "8accbe92e693e4194e0959737b02a7859261d8b2")
library(foreach)
library(doSNOW)
library(doRNG)
library(trust)
library(DRDID)
#-----------------------------------------------------------------------------
# Source my functions
#source(paste0(address, "/", "dgps.R", sep=""))
source(paste0(address, "/", "dgps.KS.R", sep=""))
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Set seed
set.seed(seed1)
#-----------------------------------------------------------------------------
################################################################
# Run the simulations for all DGPs and all sample sizes (no bootstrap)
bboot <- F
n <- 200
#---------------------------------------------------------------------------
#                          Data generating
#---------------------------------------------------------------------------
#Generate the data
data.did <- dgps(dgp,n)
y0 <- data.did$y0
y1 <- data.did$y1
d <-  data.did$d
x <-  data.did$x
att.true <- data.did$att
att.unf <- data.did$att.unf
eff <- data.did$eff
#---------------------------------------------------------------------------
############################################################################
##############          IMPROVED DR ESTIMATOR               ###############
############################################################################
#---------------------------------------------------------------------------
# Improved DR estimator
dr.imp <- DRDID::drdid_imp_panel(y1, y0, d, x, boot = bboot)
data.did <- dgps(dgp,n)
y0 <- data.did$y0
y1 <- data.did$y1
d <-  data.did$d
x <-  data.did$x
att.true <- data.did$att
att.unf <- data.did$att.unf
eff <- data.did$eff
#-------------------------------
dgp=1
#---------------------------------------------------------------------------
#                          Data generating
#---------------------------------------------------------------------------
#Generate the data
data.did <- dgps(dgp,n)
y0 <- data.did$y0
y1 <- data.did$y1
d <-  data.did$d
x <-  data.did$x
att.true <- data.did$att
att.unf <- data.did$att.unf
eff <- data.did$eff
DRDID::drdid_imp_panel(y1, y0, d, NULL, boot = bboot)
detach("package:DRDID", unload = TRUE)
library(DRDID)
#---------------------------------------------------------------------------
############################################################################
##############          IMPROVED DR ESTIMATOR               ###############
############################################################################
#---------------------------------------------------------------------------
# Improved DR estimator
dr.imp <- DRDID::drdid_imp_panel(y1, y0, d, x=NULL, boot = bboot)
#---------------------------------------------------------------------------
############################################################################
##############          IMPROVED DR ESTIMATOR               ###############
############################################################################
#---------------------------------------------------------------------------
# Improved DR estimator
dr.imp <- DRDID::drdid_imp_panel(y1, y0, d, NULL, boot = bboot)
dr.imp
#---------------------------------------------------------------------------
############################################################################
##############               DR ESTIMATOR                  #################
##############            TRADITIONAL APPROACH             #################
############################################################################
#---------------------------------------------------------------------------
# Traditional DR
#dr.tr <- dr.did.panel.tr.linear(y1, y0, d, x, x, boot = bboot, stabilized = T)
dr.tr <- DRDID::drdid_panel(y1, y0, d, NULL, boot = bboot)
dr.tr
detach("package:DRDID", unload = TRUE)
#------------------------------------------------------------------------------------------------------
#      Application: DR ATT estimators based on DID
#      Smith and Todd, 2005 (JoE)
#      Selection effect
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# MODIFIED    :   August 24, 2019
# AUTHOR      :   Pedro H. C. Sant'Anna
# AFFILIATION :   Vanderbilt University
# EMAIL       :   pedro.h.santanna@vanderbilt.edu
# AUTHOR      :   Jun Zhao
# AFFILIATION :   Vanderbilt University
# EMAIL       :   jun.zhao@vanderbilt.edu
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# Startup - clear memory, load packages, set working directory, and import the dataset
# Clear memory
rm(list=ls())
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# Set the Working Directory
address <- "C:/Users/santanph/Dropbox/Co-authored Projects/Doubly Robust DID/JoE/Final/Application"
setwd(address)
#-----------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# Functions for the applications
# function to do Implement all DID estimators at once
source(paste0(address, "/", "all.did.estimators.R", sep=""))
# Function to implement all DID estimators for each subsample
source(paste0(address, "/", "all.did.subsample.R", sep=""))
# Function to generate Tables
source(paste0(address, "/", "out.table.lalonde.R", sep=""))
#------------------------------------------------------------------------------------------------------
# load the necessary libraries
devtools::install_github("pedrohcgs/DRDID")
library(DRDID)
library(sem)
library(foreign)
library(readstata13)
library(matlib)
library(trust)
#------------------------------------------------------------------------------------------------------
# import the data
ST_2005 <- read.dta13(paste(address,"/data/nsw.dta",sep = ""),
missing.type=T)
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# Create Subsamples
source(paste0(address, "/", "subsamples.R", sep=""))
#------------------------------------------------------------------------------------------------------
set.seed(123)
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
#####################             #CPS Comparison group       ##############################
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# Evaluation bias
#------------------------------------------------------------------------------------------------------
# Lalonde sample
eval.cps.lalonde <- all.did.subsample(eval.lalonde.cps)
# DW sample
eval.cps.dw <- all.did.subsample(eval.dw.cps)
# Early RA sample
eval.cps.early <- all.did.subsample(eval.early.cps)
#------------------------------------------------------------------------------------------------------
# generate tables
eval.cps.lalonde.tab <- out.table.lalonde(eval.cps.lalonde, benchmark = 886)
eval.cps.dw.tab <- out.table.lalonde(eval.cps.dw, benchmark = 1794)
eval.cps.early.tab <- out.table.lalonde(eval.cps.early, benchmark = 2748)
# Put the tables together
cps.eval.bias <- cbind(eval.cps.lalonde.tab,
eval.cps.dw.tab,
eval.cps.early.tab)
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
save.image(paste0(address, "/", "results","/Smith-Todd-application.Rdata", sep=""))
#------------------------------------------------------------------------------------------------------
# Save CSV
out.eval <- paste0("ST-eval-CPS.csv")
out.eval <- paste0(address, "/", "results","/", out.eval, sep="")
write.csv(cps.eval.bias, file = out.eval)
source('C:/Users/santanph/Dropbox/Co-authored Projects/Doubly Robust DID/JoE/Final/Application/Main-ST-CPS.R')
source('C:/Users/santanph/Dropbox/Co-authored Projects/Doubly Robust DID/JoE/Final/Application/Main-ST-CPS.R')
