# # # # library(MASS) # rm(list=ls(all=TRUE)) # # # Read.ord Function # # Purpose: Defines function read.ord which reads in roll call data in the # format of the .ord files found on Keith Poole's webpages. # # Jeff Lewis (June 2005) # read.ord <- function(rc.file) { # Standard fields and their widths rc.fields <- c("cong","id","state","dist","lstate","party", "eh1","eh2","name") rc.fieldWidths <- c(3,5,2,2,7,4,1,1,11) # figure out how many vote columns are in the file by reading in the first line # (seems like read.fwf should handle this, but I don't see how...) read.table(file=rc.file,sep="|",as.is=TRUE, nrows=1) recl <- nchar( read.table(file=rc.file,sep="|",as.is=TRUE, nrows=1)[1,] ) votes <- recl - sum(rc.fieldWidths) # Append format and labels for votes rc.fields <- append(rc.fields,paste("V",1:votes,sep="")) rc.fieldWidths <- append(rc.fieldWidths,rep(1,votes)) # Read the vote data from fwf read.fwf(file=rc.file,widths=rc.fieldWidths,as.is=TRUE,col.names=rc.fields) } # # # ############################## # # Read the Roll Call Data # # ############################## # rcdta <- read.ord("c:/dtaord/hou110kh.ord") dim(rcdta) rcdtax <- read.ord("c:/dtaord/hou111kh.ord") dim(rcdtax) # # # 110 1110 1 8 3 88 47 REFORM MORTGAGE LENDING (PASS) # 11 15 2007 1.250 0.460 0.359 -0.486 # 269 10 22 117 15 291 0 0 0 0 127 0 0 14 # 111 241 1 3 0 47 0 SET STANDARDS FOR MORTGAGE LENDERS (PASS) # 5 7 2009 # 0 300 0 0 0 0 114 0 0 0 # 110 1110 0.279 0.536 0.336 0.101 # 111 241 0.236 0.544 0.471 0.161 # # &&&&&&&&&&&&&&&&&&&&&&&& ncong <- 110 nrollcall <- 1110 nrollcall2 <- 1110 # &&&&&&&&&&&&&&&&&&&&&&&& # &&&&&&&&&&&&&&&&&&&&&&&& ncongx <- 111 nrollcallx <- 241 nrollcall2x <- 241 # &&&&&&&&&&&&&&&&&&&&&&&& # # # Dimension Weights for 1 - 111 Scaling: House 0.4063, Senate 0.5113 # WEIGHT <- 0.4063 WEIGHT2 <- WEIGHT #WEIGHT2 <- 1.0 # # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # Read Legislator Coordinates # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # rcx.file <- "d:/atime2009/HL01111E21_PRES.DAT" # # Standard fields and their widths -- OC output Legislators # rcx.fields <- c("cong","id","state","dist","lstate","party", "name","dwnom1","dwnom2","se1","se2", "LogL","nchoice","nerror","gmp") rcx.fieldWidths <- c(4,6,3,2,8,5,12,7,7,7,7,12,5,5,7) # # Input Legislator Coordinates # TT <- read.fwf(file =rcx.file,widths=rcx.fieldWidths,as.is=TRUE,col.names=rcx.fields) dim(TT) # # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # Read Roll Call Coordinates # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # rcy.file <- "D:/atime2009/HC01111E21_PRES.DAT" # # Standard fields and their widths -- DW-NOMINATE Roll Call Parameters # rcy.fields <- c("cong","icount","dl1","zml1","dl2","zml2") rcy.fieldWidths <- c(3,5,7,7,7,7) # # Input Roll Call Coordinates # TTT <- read.fwf(file =rcy.file,widths=rcy.fieldWidths,as.is=TRUE,col.names=rcy.fields) dim(TTT) # # # T <- TT[TT[,1]==ncong,] T[,9] <- T[,9]*WEIGHT2 idno <- T[,2] party <- T[,6] state <- T[,3] # # Match up the Roll Call Vote From the Raw Data # With Scaled Legislators # # vote <- rep(0,length(idno)) dim(vote) <- c(length(idno)) vote2 <- rcdta[,9+nrollcall] ijinc <- length(rcdta[,1]) - length(idno) i <- 1 while (i <= length(idno)){ j <- i while (j <= i+ijinc){ if (idno[i]== rcdta[j,2]) { # # Catch President # if (idno[i] <= 99899){ vote[i] <- vote2[j] } } j <- j + 1 } i <- i + 1 } yeayea <- vote==1 naynay <- vote==6 kpyea <- sum(yeayea) kpnay <- sum(naynay) # # TRC <- TTT[TTT[,1]==ncong,] # nrowrc <- length(TRC[,1]) ncolrc <- length(TRC[1,]) # DL1 <- TRC[nrollcall2,3] ZM1 <- TRC[nrollcall2,4] DL2 <- TRC[nrollcall2,5] ZM2 <- TRC[nrollcall2,6] # # SECOND ROLL CALL # # # TX <- TT[TT[,1]==ncongx,] TX[,9] <- TX[,9]*WEIGHT2 idnox <- TX[,2] partyx <- TX[,6] statex <- TX[,3] # # Match up the Roll Call Vote From the Raw Data # With Scaled Legislators # # votex <- rep(0,length(idnox)) dim(votex) <- c(length(idnox)) vote2x <- rcdtax[,9+nrollcallx] ijinc <- length(rcdtax[,1]) - length(idnox) i <- 1 while (i <= length(idnox)){ j <- i while (j <= i+ijinc){ if (idnox[i] == rcdtax[j,2]) { # # Catch President # if (idnox[i] <= 99899){ votex[i] <- vote2x[j] } } j <- j + 1 } i <- i + 1 } yeayeax <- votex==1 naynayx <- votex==6 kpyeax <- sum(yeayeax) kpnayx <- sum(naynayx) # # TRCX <- TTT[TTT[,1]==ncongx,] # nrowrcx <- length(TRCX[,1]) ncolrcx <- length(TRCX[1,]) # DL1X <- TRCX[nrollcall2x,3] ZM1X <- TRCX[nrollcall2x,4] DL2X <- TRCX[nrollcall2x,5] ZM2X <- TRCX[nrollcall2x,6] # # MATCH UP THE VOTES # maxlength <- max(length(idno),length(idnox)) voteboth <- rep(0,8*maxlength) dim(voteboth) <- c(maxlength,8) # kk <- 0 i <- 1 while (i <= length(idno)){ j <- 1 while (j <= length(idnox)){ if (idno[i] == idnox[j]) { kk <- kk + 1 voteboth[kk,1] <- idno[i] voteboth[kk,2] <- idnox[j] voteboth[kk,3] <- party[i] voteboth[kk,4] <- partyx[j] voteboth[kk,5] <- T[i,8] voteboth[kk,6] <- TX[j,8] voteboth[kk,7] <- vote[i] voteboth[kk,8] <- votex[j] } j <- j + 1 } i <- i + 1 } voteboth2 <- rep(0,8*kk) dim(voteboth2) <- c(kk,8) i <- 1 while (i <= kk){ j <- 1 while (j <= 8){ voteboth2[i,j] <- voteboth[i,j] j <- j + 1 } i <- i + 1 } # plot(voteboth2[,5],voteboth2[,6],type="n",asp=1,main="", xlab="", ylab="", xlim=c(-1.0,1.0),ylim=c(-1.0,1.0),font=2,cex=1.2) # Main title mtext("House: Miller Mortgage Reform Act\n2007 Vote vs. 2009 Vote",side=3,line=1.50,cex=1.2,font=2) # x-axis title mtext("15 November 2007 Vote",side=1,line=3.25,cex=1.2) # y-axis title mtext("7 May 2009 Vote",side=2,line=2.5,cex=1.2) # # Democrats YES-YES points(voteboth2[voteboth2[,3] == 100 & voteboth2[,7] == 1 & voteboth2[,8] == 1,5], voteboth2[voteboth2[,3] == 100 & voteboth2[,7] == 1 & voteboth2[,8] == 1,6],pch='d',col="red",font=2) # Democrats NO-NO points(voteboth2[voteboth2[,3] == 100 & voteboth2[,7] == 6 & voteboth2[,8] == 6,5], voteboth2[voteboth2[,3] == 100 & voteboth2[,7] == 6 & voteboth2[,8] == 6,6],pch='d',col="blue",font=2) # Democrats NO-YES points(voteboth2[voteboth2[,3] == 100 & voteboth2[,7] == 6 & voteboth2[,8] == 1,5], voteboth2[voteboth2[,3] == 100 & voteboth2[,7] == 6 & voteboth2[,8] == 1,6],pch='d',col="black",font=2) # Democrats YES-NO points(voteboth2[voteboth2[,3] == 100 & voteboth2[,7] == 1 & voteboth2[,8] == 6,5], voteboth2[voteboth2[,3] == 100 & voteboth2[,7] == 1 & voteboth2[,8] == 6,6],pch='d',col="black",font=2) # # Republicans NO-NO points(voteboth2[voteboth2[,3] == 200 & voteboth2[,7] == 6 & voteboth2[,8] == 6,5], voteboth2[voteboth2[,3] == 200 & voteboth2[,7] == 6 & voteboth2[,8] == 6,6],pch='r',col="blue",font=2) # Republicans YES-YES points(voteboth2[voteboth2[,3] == 200 & voteboth2[,7] == 1 & voteboth2[,8] == 1,5], voteboth2[voteboth2[,3] == 200 & voteboth2[,7] == 1 & voteboth2[,8] == 1,6],pch='r',col="red",font=2) # Republicans NO-YES points(voteboth2[voteboth2[,3] == 200 & voteboth2[,7] == 6 & voteboth2[,8] == 1,5], voteboth2[voteboth2[,3] == 200 & voteboth2[,7] == 6 & voteboth2[,8] == 1,6],pch='r',col="black",font=2) # Republicans YES-NO points(voteboth2[voteboth2[,3] == 200 & voteboth2[,7] == 1 & voteboth2[,8] == 6,5], voteboth2[voteboth2[,3] == 200 & voteboth2[,7] == 1 & voteboth2[,8] == 6,6],pch='r',col="black",font=2) # lines(c(0.536,0.536),c(-1.0,1.0),lty=1) lines(c(-1.0,1.0),c(0.536,0.536),lty=1) text(-0.5, 0.0,"d = Demo. Yea\non both",col="red",font=2) text( 0.85, 0.00,"r = Repub. Yea\non both",col="red",font=2) text( 0.85, 0.20,"r = Repub. Nay\non both",col="blue",font=2) text( 0.85, 0.40,"r = Repub.\nNay/Yea or Yea/Nay",col="black",font=2) # text( 0.25,-0.50,"Cutpoint = 0.536\n 2007",col="black",font=2) text( 0.25, 0.65,"Cutpoint = 0.544\n 2009",col="black",font=2) # # SET POLARITY HERE # polarity <- voteboth2[,5] - ZM1 # errors1 <- voteboth2[,7]==1 & polarity >= 0 errors2 <- voteboth2[,7]==6 & polarity <= 0 errors3 <- voteboth2[,7]==1 & polarity <= 0 errors4 <- voteboth2[,7]==6 & polarity >= 0 kerrors12 <- sum(errors1)+sum(errors2) kerrors34 <- sum(errors3)+sum(errors4) if (kerrors12 >= kerrors34){ yeaerror <- errors3 nayerror <- errors4 } if (kerrors12 < kerrors34){ yeaerror <- errors1 nayerror <- errors2 } kerrorsmin <- min(kerrors12,kerrors34) # # polarityx <- voteboth2[,6] - ZM1X # errors1x <- voteboth2[,8]==1 & polarityx >= 0 errors2x <- voteboth2[,8]==6 & polarityx <= 0 errors3x <- voteboth2[,8]==1 & polarityx <= 0 errors4x <- voteboth2[,8]==6 & polarityx >= 0 kerrors12x <- sum(errors1x)+sum(errors2x) kerrors34x <- sum(errors3x)+sum(errors4x) if (kerrors12x >= kerrors34x){ yeaerrorx <- errors3x nayerrorx <- errors4x } if (kerrors12x < kerrors34x){ yeaerrorx <- errors1x nayerrorx <- errors2x } kerrorsminx <- min(kerrors12x,kerrors34x) ryearyea <- (voteboth2[,3] == 200 & voteboth2[,7] == 1 & voteboth2[,8] == 1)