year 2004 VARS VCF0301 VCF0704 VCF0704A VCF0724 VCF0803 VCF9088 VCF9096 ; # one-way frequency tables (always important to examine these) xtable VCF0301 xtable VCF0704 xtable VCF0704A xtable VCF0724 xtable VCF0803 xtable VCF9088 xtable VCF9096 # get rid of unwanted value in party ID pid <- VCF0301; pid <- ifelse(pid == 9, NA, pid); # get rid of unwanted value in libcon self-placement libcon <- VCF0803; libcon <- ifelse(libcon == 9, NA, libcon); # presvote3 is three major party candidates only: Dem (1), Rep (2), Third (3) presvote3 <- VCF0704; # presvote is Dem (0) and Rep (1) candidates only presvote <- VCF0704A - 1; # watchtv is how much watched campaign on TV: no (1), yes (2) watchtv <- VCF0724; # one-way frequency tables xtable pid xtable libcon xtable presvote3 xtable presvote xtable watchtv # crosstab of libcon given pid xtable libcon pid # crosstab of libcon given pid and watchtv xtable libcon pid watchtv # crosstab of three-party vote given pid xtable presvote3 pid # crosstab of two-party vote given pid xtable presvote pid # compute spatial model measure of difference between Dem and Rep candidates demlibcon <- VCF9088; replibcon <- VCF9096; demdist <- abs(libcon-demlibcon); repdist <- abs(libcon-replibcon); distdiff <- demdist-repdist; # one-way frequency table of party placements and spatial model distances xtable demlibcon xtable replibcon xtable demdist xtable repdist xtable distdiff # crosstab of two-party vote given spatial difference xtable presvote distdiff # simple ordinary least squares regression model of two-party vote # explanatory variables are PID dummy variables and spatial model difference summary(lm(presvote ~ factor(pid) + distdiff, weights=wgtXXX)); # simple probit regression model of two-party vote # explanatory variables are PID dummy variables and spatial model difference summary(glm(presvote ~ factor(pid) + distdiff, family=binomial(link="probit"), weights=wgtXXX));