library(haven)
library(foreign)
library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(broom)
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
library(readr)
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
library(car)
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(alr3)
##
## Attaching package: 'alr3'
## The following object is masked from 'package:MASS':
##
## forbes
library(zoo)
library(nortest)
library(plotrix)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:plotrix':
##
## rescale
## The following object is masked from 'package:readr':
##
## col_factor
library(tableone)
library(Weighted.Desc.Stat)
library(mitools)
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(questionr)
library(grid)
library(Matrix)
library(survival)
anes2016<-read_dta("C:\\Users\\Jaire\\OneDrive\\Desktop\\Stats for Dem Data 2\\Homework 2\\ANES2016.dta")
How do demographic characteristics influence support and opposition toward the Patient Protection and Affordable Care Act of 2010?
anes2016$favACA<-as.factor(anes2016$V161113)
anes2016$favACA<- recode(anes2016$favACA, recodes = "1=1; 2:3=0; -8=NA")
table(anes2016$favACA)
##
## 0 1
## 2689 1578
# Sex
anes2016$males<-as.factor(anes2016$V161342)
anes2016$males<- recode(anes2016$males, recodes = "1=1; 2:3=0; -9=NA")
table(anes2016$males)
##
## 0 1
## 2243 1987
# Age
anes2016$Agec<-recode(anes2016$V161267, recodes = "-9:-8=NA")
table(anes2016$Agec)
##
## 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
## 28 39 54 53 44 56 55 63 70 70 60 60 69 78 86 73 81 79 69 85 66 75 51 66 67 51
## 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
## 46 70 83 66 53 67 59 72 59 81 78 78 88 76 94 96 89 80 69 72 75 69 88 78 94 55
## 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
## 54 49 53 38 45 34 41 26 29 21 24 24 24 12 13 12 14 9 12 6 27
# non-Hispanic white race
anes2016$nhwhite<-as.factor(anes2016$V161310X)
anes2016$nhwhite<-recode(anes2016$nhwhite, recodes = "1=1; 2:6=0;-9=NA")
table(anes2016$nhwhite)
##
## 0 1
## 1200 3038
# non-Hispanic black race
anes2016$nhblack<-as.factor(anes2016$V161310X)
anes2016$nhblack<-recode(anes2016$nhblack, recodes = "1=0; 2=1; 3:6=0;-9=NA")
table(anes2016$nhblack)
##
## 0 1
## 3840 398
# Hispanic race
anes2016$Hispanic<-as.factor(anes2016$V161310X)
anes2016$Hispanic<-recode(anes2016$Hispanic, recodes = "5=1; 1:4=0; 6=0;-9=NA")
table(anes2016$Hispanic)
##
## 0 1
## 3788 450
# other race
anes2016$otherrace<-as.factor(anes2016$V161310X)
anes2016$otherrace<-recode(anes2016$otherrace, recodes = "3=1; 4=1; 6=1; 1:2=0; 5=0;-9=NA")
table(anes2016$otherrace)
##
## 0 1
## 3886 352
# famliy income
anes2016$familyincome<-recode(anes2016$V168023, recodes = "-9:-1=NA")
table(anes2016$familyincome)
##
## 1 2 3 4 5 6 7
## 87 183 247 246 152 153 23
sub<-dplyr::select(anes2016, favACA,nhwhite,nhblack,Hispanic,otherrace,familyincome,males) %>%
filter(complete.cases(.))
options(survey.lonely.psu = "adjust")
des<-svydesign(nest = TRUE, ids=~anes2016$V160202, strata =~anes2016$V160201, weights =~anes2016$V160101, data=anes2016)
fit.logit<-svyglm(favACA~nhwhite+nhblack+Hispanic+otherrace+familyincome+males,
design= des,
family=binomial)
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
summary(fit.logit)
##
## Call:
## svyglm(formula = favACA ~ nhwhite + nhblack + Hispanic + otherrace +
## familyincome + males, design = des, family = binomial)
##
## Survey design:
## svydesign(nest = TRUE, ids = ~anes2016$V160202, strata = ~anes2016$V160201,
## weights = ~anes2016$V160101, data = anes2016)
##
## Coefficients: (1 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.37289 0.35982 -1.036 0.30893
## nhwhite1 -0.72861 0.25426 -2.866 0.00781 **
## nhblack1 1.20917 0.36501 3.313 0.00256 **
## Hispanic1 -0.08143 0.33244 -0.245 0.80829
## familyincome 0.17127 0.06418 2.668 0.01253 *
## males1 -0.21918 0.16977 -1.291 0.20724
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 0.9377897)
##
## Number of Fisher Scoring iterations: 4
knitr::kable(data.frame(OR = exp(coef(fit.logit)), ci=exp(confint(fit.logit))))
OR | ci.2.5.. | ci.97.5.. | |
---|---|---|---|
(Intercept) | 0.6887433 | 0.3402316 | 1.3942484 |
nhwhite1 | 0.4825803 | 0.2931833 | 0.7943282 |
nhblack1 | 3.3507180 | 1.6384659 | 6.8523312 |
Hispanic1 | 0.9217997 | 0.4804622 | 1.7685363 |
familyincome | 1.1868127 | 1.0465207 | 1.3459116 |
males1 | 0.8031767 | 0.5758431 | 1.1202578 |
How do demographic characteristics influence support and opposition toward the Patient Protection and Affordable Care Act of 2010?
Based on the logit model, non-Hispanic whites are significantly less likely to favor the Patient Protection and Affordable Care Act of 2010 than non-Hispanic other race. Non-Hispanic blacks are significantly more likely to favor the Patient Protection and Affordable Care Act of 2010 than non-Hispanic other race. Additionally, as family income increases the likelihood of favoring the Patient Protection and Affordable Care Act of 2010 significantly increases.