diff --git a/CTV2019.R b/CTV2019.R new file mode 100644 index 0000000..c292f43 --- /dev/null +++ b/CTV2019.R @@ -0,0 +1,74 @@ +################################################################################ +## The Regression Discontinuity Design -- Re-analysis of Klasnja-Titiunik (2017) +## Authors: Matias Cattaneo, Rocio Titiunik, Gonzalo Vazquez-Bare +## Last update: 10-Jun-2019 +################################################################################ +## SOFTWARE WEBSITE: https://sites.google.com/site/rdpackages/ +################################################################################ +## TO INSTALL/DOWNLOAD R PACKAGES/FUNCTIONS: +## RDROBUST: install.packages('rdrobust') +## RDDENSITY: install.packages("rddensity",dependencies=TRUE) +## RDLOCRAND: install.packages('rdlocrand') +################################################################################ + +rm(list = ls()) + +library(rdrobust) +library(rddensity) +library(rdlocrand) + + +################################# +# Read data and define variables +################################# + +data = read.csv("CTV_2019_Sage.csv") + +Y = data$mv_incpartyfor1 +X = data$mv_incparty + +covs = data[, c("pibpc", "population", "numpar_candidates_eff", "party_DEM_wonlag1_b1", "party_PSDB_wonlag1_b1", "party_PT_wonlag1_b1", "party_PMDB_wonlag1_b1")] +covsnm = c("GDP per capita", "Population", "No. Effective Parties", "DEM Victory t-1", "PSDB Victory t-1", "PT Victory t-1", "PMDB Victory t-1") + + +################################# +# Falsification analysis +################################# + +rddens = rddensity(X) +summary(rddens) +rdplotdensity(rddens, X = data$mv_incparty[!is.na(data$mv_incparty)], + xlab = "Incumbent Party's Margin of Victory at t", ylab = "Estimated density") + +for(c in 1:ncol(covs)){ + summary(rdrobust(covs[,c],X)) + rdplot(covs[,c],X,y.label=covsnm[c],x.label="Incumbent Party's Margin of Victory", + x.lim= c(-30,30),binselect = "qsmv") +} + + +################################# +# Outcome analysis +################################# + +# rdplot + +rdplot(Y,X) + +# Continuity-based approach + +rdr = rdrobust(Y,X) +summary(rdr) + +# with covariates + +rdrcovs = rdrobust(Y,X,covs=covs) +summary(rdrcovs) + +# Local randomization approach + +rdwin = rdwinselect(X,covs,wmin=0.05,wstep=0.01,nwindows=200,seed=765,plot=TRUE) +w = 0.15 + +rdrand = rdrandinf(Y,X,wl=-w,wr=w,reps=1000,seed=765) + diff --git a/CTV2019.do b/CTV2019.do new file mode 100644 index 0000000..0dadaf3 --- /dev/null +++ b/CTV2019.do @@ -0,0 +1,79 @@ +******************************************************************************** +** The Regression Discontinuity Design -- Re-analysis of Klasnja Titiunik (2017) +** Authors: Matias D. Cattaneo, Rocio Titiunik and Gonzalo Vazquez-Bare +** Last update: 10-JUN-2019 +******************************************************************************** +** SOFTWARE WEBSITE: https://sites.google.com/site/rdpackages/ +******************************************************************************** +** TO INSTALL STATA PACKAGES: +** RDROBUST: net install rdrobust, from(https://sites.google.com/site/rdpackages/rdrobust/stata) replace +** RDDENSITY: net install rddensity, from(https://sites.google.com/site/rdpackages/rddensity/stata) replace +** RDLOCRAND: net install rdlocrand, from(https://sites.google.com/site/rdpackages/rdlocrand/stata) replace +******************************************************************************** +* Score: mv_incparty (margin of victory of incumbent party at t) +* Outcome: indicator for victory of incumbent party at t+1 +* Cutoff: 0 +******************************************************************************** + + +******************************************************************************** +** Load Data +******************************************************************************** + +use "CTV_2019_Sage.dta", clear + +global y mv_incpartyfor1 +global x mv_incparty +global covs "pibpc population numpar_candidates_eff party_DEM_wonlag1_b1 party_PSDB_wonlag1_b1 party_PT_wonlag1_b1 party_PMDB_wonlag1_b1" + + +******************************************************************************** +** Falsification analysis +******************************************************************************** + +* Density discontinuity test + +rddensity $x, plot + +* Placebo tests on pre-determined covariates + +foreach var of global covs { + rdrobust `var' $x + qui rdplot `var' $x if abs($x)<=30, graph_options(graphregion(color(white)) /// + xlabel(-30(10)30) /// + ytitle(`var')) +} + + +******************************************************************************** +* Outcome analysis +******************************************************************************** + +* RD plot + +rdplot $y $x, graph_options(graphregion(color(white)) /// + xtitle(Margin of Victory at t) /// + ytitle(Margin of Victory at t+1)) + +* Continuity based approach + +rdrobust $y $x + +* with covariates + +rdrobust $y $x, covs($covs) + + +* Local randomization approach + +* Window selector: uncomment to run. Can take a long time. + +*rdwinselect $x $covs, wmin(0.05) wstep(0.01) nwindows(200) seed(765) plot graph_options(xtitle(Half window length) ytitle(Minimum p-value across all covariates) graphregion(color(white))) + +* Randomization inference + +local w = 0.15 +rdrandinf $y $x, wl(-`w') wr(`w') reps(1000) seed(765) + + +