# # # # basicspace_AM_Vietnam_1968_Stata_Bootstrap.r -- Does Aldrich-McKelvey Scaling of 1968 Vietnam # 7-Point Scale # # &&&&&&&&& STIMULI &&&&&&&& # # 1968 7-POINT VIETNAM SCALE # # VAR00466 LOC 913 WIDTH 1 VNAM HALK/DOVE-JHNSN # VAR00467 LOC 914 WIDTH 1 VNAM HALK/DOVE-HHH # VAR00468 LOC 915 WIDTH 1 VNAM HALK/DOVE-NIXON # VAR00469 LOC 916 WIDTH 1 VNAM HALK/DOVE-WALLA # VAR00470 LOC 917 WIDTH 1 VNAM HALK/DOVE-R # CAND(1)= 'LYNDON JOHNSON ' # CAND(2)= 'HUBERT HUMPHREY ' # CAND(3)= 'RICHARD NIXON ' # CAND(4)= 'GEORGE WALLACE ' # CAND(5)= 'INDIVIDUAL ' # rm(list=ls(all=TRUE)) # library(MASS) library(foreign) library(basicspace) library(gdata) setwd("C:/basicspace_examples") data <- read.dta("ftp://voteview.com/wf1/nes1968_first_11.dta") attach(data,warn.conflicts = FALSE) # T <- cbind(VAR00466,VAR00467,VAR00468,VAR00469,VAR00470) TT <- T mode(TT) <- "double" colnames(TT) <- c("Johnson","Humphrey","Nixon","Wallace","Self") # # Note that polarity=1 selects Lyndon Johnson -- The Respondent Self Placement # is in the last column -- respondent=5 # # Setup Bootstrap Loop # Ntrials = 100 result <- vector("list", Ntrials) # #result <- aldmck(TT,polarity=1,respondent=5,missing=c(0,8,9),verbose=TRUE) # for(i in 1:Ntrials) result[[i]] <- aldmck(data=TT[sample(1:nrow(TT),nrow(TT),replace=TRUE),], polarity=1, respondent=5, missing=c(0,8,9),verbose=TRUE) final <- matrix(NA,nrow=length(result[[1]]$stimuli),ncol=Ntrials) for(i in 1:Ntrials) final[,i] <- result[[i]]$stimuli std.error <- apply(final,1,sd) names(std.error) <- names(result[[1]]$stimuli) # # ---- Useful Commands To See What is in an Object # # > length(result) # [1] 8 # > class(result) # [1] "aldmck" # > names(result) # [1] "stimuli" "respondents" "eigenvalues" "AMfit" "R2" # [6] "N" "N.neg" "N.pos" # > summary(result) -- shows everything # > plot(result) -- shows basic graphs of the results # # result.original <- aldmck(data=TT, polarity=1, respondent=5, missing=c(0,8,9),verbose=TRUE) TOUT <- rep(0,2*4) dim(TOUT) <- c(2,4) TOUT[1,] <- formatC(result.original$stimuli,digits=5,width=10,format="f") TOUT[2,] <- formatC(std.error,digits=5,width=10,format="f") # rownames(TOUT) <- c("Coordinate","StdErr") # final <- rbind(names(result.original$stimuli),TOUT) # write.fwf(x=format(as.data.frame(final),digits=5,width=10,scientific=FALSE),quote=FALSE,rownames=TRUE,colnames=FALSE,"1968_Stimuli.txt")