# # Barry Edwards # Replication file for Formulating Voting Rights Act Remedies to Address Current Conditions # # Purpose of this program is to run repeated regression models on cross-sections by year # to calculate the coefficients needed to generate the 3-D figure in the paper # This code generates a figure used to check work, it does not appear in paper. # # Remove all objects just to be safe # rm(list=ls(all=TRUE)) # library(foreign) # # data.stata <- read.dta("http://www.poliscidata.com/replication/vra/edwardsDataVotingRights.dta") attach(data.stata) ################## curves over time for African American representation minYear <- 93 # note hispanicVAP not avail from 87-92 maxYear <- 112 thisYear <- 93 logitCoefficient <- NULL logitConstant <- NULL seRange <- NULL seLower <- NULL seUpper <- NULL logitCoefficientNE <- NULL seRangeNE <- NULL seLowerNE <- NULL seUpperNE <- NULL bvapCoeff <- NULL hvapCoeff <- NULL section5stateCoeff <- NULL medFamIncomeCoeff <- NULL demVoteCoeff <- NULL whiteIncumbentCoeff <- NULL bvapMean <- NULL hvapMean <- NULL section5stateMean <- NULL medFamIncomeMean <- NULL demVoteMean <- NULL whiteIncumbentMean <- NULL northeastRegionCoeff <- NULL northeastRegionMean <- NULL openSeatCoeff <- NULL openSeatMean <- NULL afamYearMeanConstant <- NULL while (thisYear <= maxYear) { oneYearData <- subset(data.stata,data.stata$cong==thisYear) oneYearModel <- glm(oneYearData$repIsBlack ~ oneYearData$blackVAP + oneYearData$hispanicVAP + oneYearData$whiteIncumbent + oneYearData$openSeat, family=binomial(link = "logit")) yearResults <- as.numeric(oneYearModel$coefficients) yearResults[3] logitCoefficient[thisYear] <- yearResults[3] seRange <- confint(oneYearModel)[3,] seLower[thisYear] <- as.numeric(seRange[1]) seUpper[thisYear] <- as.numeric(seRange[2]) logitConstant[thisYear] <- yearResults[1] bvapCoeff[thisYear] <- yearResults[2] hvapCoeff[thisYear] <- yearResults[3] whiteIncumbentCoeff[thisYear] <- yearResults[4] openSeatCoeff[thisYear] <- yearResults[5] bvapMean[thisYear] <- mean(na.omit(oneYearData$blackVAP)) hvapMean[thisYear] <- mean(na.omit(oneYearData$hispanicVAP)) section5stateMean[thisYear] <- mean(na.omit(oneYearData$section5state)) medFamIncomeMean[thisYear] <- mean(na.omit(oneYearData$medianFamilyIncome)) demVoteMean[thisYear] <- mean(na.omit(oneYearData$demSharePresVote)) whiteIncumbentMean[thisYear] <- mean(na.omit(oneYearData$whiteIncumbent)) northeastRegionMean[thisYear] <- mean(na.omit(oneYearData$northeastRegion)) openSeatMean[thisYear] <- mean(na.omit(oneYearData$openSeat)) ### kludge here, using open seat coef for 1970s for two cycles where no open seat Af Am wins openSeatCoeff[94] <- -1.87 openSeatCoeff[95] <- -1.87 afamYearMeanConstant[thisYear] <- hvapCoeff[thisYear]*hvapMean[thisYear] + whiteIncumbentCoeff[thisYear]*0 + openSeatCoeff[thisYear]*1 + logitConstant[thisYear] # thisYear <- thisYear + 1 } par(mfrow=c(1,2)) par(mar=c(4.1,5.3,3.1,1.1)) year <- seq(1,maxYear,by=1) plot(x="",y="",xlim=c(minYear,maxYear),xlab="Election Cycle",ylab="Partial Regression Coefficient\nLatino VAP",ylim=c(-200,200),main="(a) African American Representation",axes=F,cex.lab=1.3 ) points(x=year,y=logitCoefficient,pch=16) lines(x=year,y=logitCoefficient) segments(year,seLower,year,seUpper,lty=2) abline(h=0,lty=3) axis(2,font=2) axis(1, at=seq(minYear,maxYear,by=1), labels=seq(1972,2010,by=2),las=1,font=2) box() ################## curves over time for Latino representation minYear <- 96 # note hispanicVAP not avail from 87-92 maxYear <- 112 thisYear <- 96 logitCoefficient <- NULL logitConstant <- NULL seRange <- NULL seLower <- NULL seUpper <- NULL bvapCoeff <- NULL hvapCoeff <- NULL section5stateCoeff <- NULL medFamIncomeCoeff <- NULL demVoteCoeff <- NULL whiteIncumbentCoeff <- NULL bvapMean <- NULL hvapMean <- NULL section5stateMean <- NULL medFamIncomeMean <- NULL demVoteMean <- NULL whiteIncumbentMean <- NULL latinoYearMeanConstant <- NULL northeastRegionCoeff <- NULL northeastRegionMean <- NULL openSeatCoeff <- NULL openSeatMean <- NULL while (thisYear <= maxYear) { oneYearData <- subset(data.stata,data.stata$cong==thisYear) oneYearModel <- glm(oneYearData$repIsLatino ~ oneYearData$hispanicVAP + oneYearData$blackVAP + oneYearData$whiteIncumbent + oneYearData$openSeat, family=binomial(link = "logit")) yearResults <- as.numeric(oneYearModel$coefficients) yearResults[3] logitCoefficient[thisYear] <- yearResults[3] logitConstant[thisYear] <- yearResults[1] hvapCoeff[thisYear] <- yearResults[2] bvapCoeff[thisYear] <- yearResults[3] whiteIncumbentCoeff[thisYear] <- yearResults[4] openSeatCoeff[thisYear] <- yearResults[5] bvapMean[thisYear] <- mean(na.omit(oneYearData$blackVAP)) hvapMean[thisYear] <- mean(na.omit(oneYearData$hispanicVAP)) medFamIncomeMean[thisYear] <- mean(na.omit(oneYearData$medianFamilyIncome)) demVoteMean[thisYear] <- mean(na.omit(oneYearData$demSharePresVote)) whiteIncumbentMean[thisYear] <- mean(na.omit(oneYearData$whiteIncumbent)) openSeatMean[thisYear] <- mean(na.omit(oneYearData$openSeat)) # kludge to fix problem of open seat perfectly predicting failure in some cycles openSeatCoeff[100] <- -1.30 openSeatCoeff[102] <- -1.30 openSeatCoeff[104] <- -1.86 openSeatCoeff[107] <- -1.86 latinoYearMeanConstant[thisYear] <- bvapCoeff[thisYear]*bvapMean[thisYear] + whiteIncumbentCoeff[thisYear]*0 + openSeatCoeff[thisYear]*1 + logitConstant[thisYear] thisYear <- thisYear + 1 } year <- seq(1,maxYear,by=1) plot(x="",y="",xlim=c(minYear,maxYear),xlab="Election Cycle",ylab="Partial Regression Coefficient\nAfrican American VAP",ylim=c(-200, 200),main="(b) Latino Representation",axes=F,cex.lab=1.3) points(x=year,y=logitCoefficient,pch=16) lines(x=year,y=logitCoefficient) segments(year,seLower,year,seUpper,lty=2) abline(h=0,lty=3) axis(2,font=2) axis(1, at=seq(minYear,maxYear,by=1), labels=seq(1978,2010,by=2),las=1,font=2) box() # when does xB = 0, that's when there's a 50% chance of minorityRepresentative = 1