library(car)
## Loading required package: carData
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
library(survey)
## Loading required package: grid
## Loading required package: Matrix
## Loading required package: survival
## 
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
## 
##     dotchart
library(ggplot2)
library(pander)
library(knitr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:car':
## 
##     recode
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(haven)
GSS <- read_sav("Desktop/GSS7216_R4.sav")

#abortion attitudes
GSS$abort<-Recode(GSS$ABANY,recodes="1='Pro-Choice'; 2='Pro-Life'; else=NA", as.factor=T)
GSS$abort<-relevel(GSS$abort,ref="Pro-Life")

GSS$black<-Recode(GSS$RACE,recodes="2=1; else=NA")

GSS$educ<-Recode(GSS$DEGREE,recodes="0='Less than HS';1='High School';2='Junior College';3='Undergraduate';4='Graduate';else=NA", as.factor=T)
GSS$educ<-relevel(GSS$educ,ref="Graduate")

GSS$marst<-Recode(GSS$MARITAL,recodes="1='Married'; 2='Widowed';3='Divorced';4='Seperated';5='Never Married'; else=NA", as.factor=T)
GSS$marst<-relevel(GSS$marst,ref="Married")

GSS$party<-Recode(GSS$PARTYID,recodes="0:2='Democrat'; 3='Independent'; 4:6='Republican';7='Other'; else=NA", as.factor=T) 
GSS$party<-relevel(GSS$party,ref="Republican")

GSS$polit<-Recode(GSS$MEMPOLIT,recodes="1='Politically Active'; 2='Not Politically Active';else=NA", as.factor=T)
GSS$polit<-relevel(GSS$polit,ref="Politically Active")

GSS$polview<-Recode(GSS$POLVIEWS,recodes="1:3='Liberal'; 4='Moderate'; 5:7='Conservative';else=NA", as.factor=T)
GSS$polview<-relevel(GSS$polview,ref="Conservative")

Creating an index out of abortion attitudes using the GSS survey. Each variable is dichotomous, and corresponds with whether the respondent believes it neccesary for a woman to have an abortion if:

The baby has potential to be born with a defect (ABDEFCT) The mother has no desire for more children (ABNOMORE) The parents are unable to afford a child (ABPOOR) The baby is result of the mother being raped (ABRAPE) The mother is single, with no partner (ABSINGLE) Any reason (ABANY)

GSS.pc<-prcomp(~ABDEFECT+ABNOMORE+ABPOOR+ABRAPE+ABSINGLE+ABANY,data=GSS, center=T, scale=T, retx=T)

#screeplot
screeplot(GSS.pc, type = "lines", main="Scree Plot")
abline(h=1)

Only one eigenvalue detected. The second component is nearly 1, but does not actually indicate strong relevance.

summary(GSS.pc)
## Importance of components:
##                           PC1    PC2     PC3     PC4     PC5     PC6
## Standard deviation     1.9912 0.9932 0.62538 0.51390 0.45402 0.43279
## Proportion of Variance 0.6608 0.1644 0.06518 0.04402 0.03436 0.03122
## Cumulative Proportion  0.6608 0.8252 0.89041 0.93443 0.96878 1.00000

Cumalative proportions indicate that the first two proponents account for about 83 percent of variation.

GSS.pc$rotation
##                PC1        PC2          PC3         PC4         PC5
## ABDEFECT 0.3257987  0.6213807 -0.711189610  0.02124629  0.03864883
## ABNOMORE 0.4477573 -0.2257782 -0.041067783 -0.06748671 -0.85969334
## ABPOOR   0.4429068 -0.1944708  0.030130056 -0.71099723  0.35994466
## ABRAPE   0.3216645  0.6343284  0.700862385  0.04091571 -0.03545223
## ABSINGLE 0.4508162 -0.2337419  0.019252729  0.04630084  0.23703237
## ABANY    0.4364617 -0.2609280  0.006017142  0.69689255  0.26913244
##                   PC6
## ABDEFECT -0.002316443
## ABNOMORE  0.056779542
## ABPOOR    0.360596186
## ABRAPE    0.004508331
## ABSINGLE -0.826698687
## ABANY     0.428123889
hist(GSS.pc$x[,1])

hist(GSS.pc$x[,2])

The first component is obviously the best, and most relevant of all listed components. The others listed do not suffice, as the coefficents are inconsistent and do not relfict solidarity.

cor(GSS.pc$x[,1:2])
##               PC1           PC2
## PC1  1.000000e+00 -1.087717e-14
## PC2 -1.087717e-14  1.000000e+00
scores<-data.frame(GSS.pc$x)
scores$name<-rownames(GSS.pc$x)
GSS$name<-rownames(GSS)
GSS<-merge(GSS, scores, by.x="name", by.y="name", all.x=F)
tail(names(GSS), 20)
##  [1] "RWEIGHT"  "RHLTHEND" "WTSS"     "WTSSNR"   "WTSSALL"  "VSTRAT"  
##  [7] "VPSU"     "abort"    "black"    "educ"     "marst"    "party"   
## [13] "polit"    "polview"  "PC1"      "PC2"      "PC3"      "PC4"     
## [19] "PC5"      "PC6"
round(cor(GSS[,c("ABDEFECT","ABNOMORE","ABPOOR","ABRAPE","ABSINGLE","ABANY")], method = "spearman"), 3)
##          ABDEFECT ABNOMORE ABPOOR ABRAPE ABSINGLE ABANY
## ABDEFECT    1.000    0.444  0.443  0.609    0.436 0.408
## ABNOMORE    0.444    1.000  0.782  0.424    0.800 0.777
## ABPOOR      0.443    0.782  1.000  0.441    0.790 0.735
## ABRAPE      0.609    0.424  0.441  1.000    0.432 0.401
## ABSINGLE    0.436    0.800  0.790  0.432    1.000 0.796
## ABANY       0.408    0.777  0.735  0.401    0.796 1.000
round(cor(GSS[,c("ABDEFECT","ABNOMORE","ABPOOR","ABRAPE","ABSINGLE","ABANY","PC1","PC2")], method = "spearman"), 3)
##          ABDEFECT ABNOMORE ABPOOR ABRAPE ABSINGLE  ABANY    PC1    PC2
## ABDEFECT    1.000    0.444  0.443  0.609    0.436  0.408  0.662  0.521
## ABNOMORE    0.444    1.000  0.782  0.424    0.800  0.777  0.874 -0.310
## ABPOOR      0.443    0.782  1.000  0.441    0.790  0.735  0.867 -0.284
## ABRAPE      0.609    0.424  0.441  1.000    0.432  0.401  0.676  0.552
## ABSINGLE    0.436    0.800  0.790  0.432    1.000  0.796  0.880 -0.319
## ABANY       0.408    0.777  0.735  0.401    0.796  1.000  0.853 -0.364
## PC1         0.662    0.874  0.867  0.676    0.880  0.853  1.000 -0.081
## PC2         0.521   -0.310 -0.284  0.552   -0.319 -0.364 -0.081  1.000
#Make the survey design object
options(survey.lonely.psu = "adjust")
GSS$pc1q<-cut(GSS$PC1, breaks=unique(quantile(GSS$PC1,probs=c(0,.25,.5,.75,1),na.rm=T)))
des<-svydesign(ids=~1, strata=~VSTRAT, weights=~WTSSALL, data=GSS)
#means of the variables in the index, by quantile of the index
svyby( ~ABDEFECT+ABNOMORE+ABPOOR+ABRAPE+ABSINGLE+ABANY,~pc1q, des,FUN=svymean , na.rm=T)
##                        pc1q ABDEFECT ABNOMORE   ABPOOR   ABRAPE ABSINGLE
## (-2.27,0.407] (-2.27,0.407] 1.052520 1.330524 1.421966 1.031833 1.390091
## (0.407,1.3]     (0.407,1.3] 1.034809 1.982097 1.868908 1.030882 1.992531
## (1.3,2.91]       (1.3,2.91] 1.814784 1.996202 1.995719 1.758433 1.999039
##                  ABANY se.ABDEFECT  se.ABNOMORE    se.ABPOOR   se.ABRAPE
## (-2.27,0.407] 1.641267 0.003565909 0.0075530665 0.0079546236 0.003004043
## (0.407,1.3]   1.929275 0.002314385 0.0016923867 0.0041264985 0.002147847
## (1.3,2.91]    1.995528 0.004804200 0.0008334128 0.0008000682 0.005407533
##                se.ABSINGLE     se.ABANY
## (-2.27,0.407] 0.0078735582 0.0077609971
## (0.407,1.3]   0.0010851662 0.0031100519
## (1.3,2.91]    0.0003929556 0.0008720987
library(ggplot2)
ggplot(aes(x=educ, y=PC1), data=GSS)+geom_boxplot()

fit.1<-svyglm(PC1~black+educ+polview+polit+marst+party, des, family=gaussian)
summary(fit.1)
## 
## Call:
## svyglm(formula = PC1 ~ black + educ + polview + polit + marst + 
##     party, design = des, family = gaussian)
## 
## Survey design:
## svydesign(ids = ~1, strata = ~VSTRAT, weights = ~WTSSALL, data = GSS)
## 
## Coefficients: (1 not defined because of singularities)
##                             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                  0.28451    0.54794   0.519 0.603738    
## educHigh School              1.02984    0.38580   2.669 0.007744 ** 
## educJunior College           0.83741    0.46238   1.811 0.070475 .  
## educLess than HS             1.43479    0.39141   3.666 0.000262 ***
## educUndergraduate            0.78313    0.43745   1.790 0.073775 .  
## polviewLiberal              -0.40930    0.14583  -2.807 0.005119 ** 
## polviewModerate             -0.43588    0.14910  -2.923 0.003553 ** 
## politNot Politically Active -0.56253    0.30994  -1.815 0.069877 .  
## marstDivorced               -0.23309    0.20448  -1.140 0.254624    
## marstNever Married          -0.64160    0.14439  -4.444 1.00e-05 ***
## marstSeperated              -0.35475    0.20571  -1.725 0.084967 .  
## marstWidowed                 0.23562    0.20877   1.129 0.259366    
## partyDemocrat               -0.12002    0.20413  -0.588 0.556716    
## partyIndependent            -0.04604    0.31424  -0.146 0.883564    
## partyOther                  -1.35997    0.32437  -4.193 3.04e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 3.32932)
## 
## Number of Fisher Scoring iterations: 2

We see variation in abortion attitudes is a bit distinct across education levels and political views. Perhaps the most interesting is the prevalence seen in those who classify as “Other” party. Further examination of this is neccesary - I intially coded this to only view attitudes across black respondents to identify distinctions between sex.