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(VGAM)
## Loading required package: stats4
## Loading required package: splines
##
## Attaching package: 'VGAM'
## The following object is masked from 'package:survey':
##
## calibrate
## The following object is masked from 'package:lmtest':
##
## lrtest
## The following object is masked from 'package:car':
##
## logit
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(sandwich)
library(pastecs)
## Warning: package 'pastecs' was built under R version 3.6.3
##
## Attaching package: 'pastecs'
## The following objects are masked from 'package:dplyr':
##
## first, last
anes2016<-read_dta("C:\\Users\\Jaire\\OneDrive\\Desktop\\Research\\Dissertation\\Data\\R Transformations\\RANES2016.dta")
table(anes2016$V161113)
##
## -8 1 2 3
## 4 1578 1808 881
# Support ACA 2010
anes2016$favACA<- recode(anes2016$V161113, recodes = "2:3='0'; -8=NA", as.factor = T)
table(anes2016$favACA)
##
## 0 1
## 2689 1578
# Self-rated Health
anes2016$SelfratedHlth<-recode(anes2016$V161115, recodes = "1='5'; 2='4'; ; 4='2';5='1';-9=NA", as.factor = T)
anes2016$SelfratedHlth<-recode(anes2016$SelfratedHlth, recodes = "1:2='Negative'; 3:5='Positive'", as.factor = T)
table(anes2016$SelfratedHlth)
##
## Negative Positive
## 750 3513
# Government Insurance Plan Preference
anes2016$GovInsur<-recode(anes2016$V161184, recodes = "1:3='1';4=NA;5:7='0'; 99=NA; -9:-8=NA", as.factor = T)
anes2016$GovInsur<-recode(anes2016$GovInsur, recodes = "1='Plan'; 0='No Plan'", as.factor = T)
table(anes2016$GovInsur)
##
## No Plan Plan
## 1599 1422
# Federal Healthcare Spending Preference
anes2016$GovIncSpHC<-recode(anes2016$V162193, recodes = "-9:-6=NA; 2:3='0'", as.factor = T)
anes2016$GovIncSpHC<-recode(anes2016$GovIncSpHC, recodes = "1='Increase';0='Decrease'", as.factor = T)
table(anes2016$GovIncSpHC)
##
## Decrease Increase
## 1908 1694
# Democrat
anes2016$Democrat<-recode(anes2016$V161155, recodes = "-9:0=NA; 2:5='0'", as.factor = T)
table(anes2016$Democrat)
##
## 0 1
## 2746 1451
# Republican
anes2016$Republican<-recode(anes2016$V161155, recodes = "-9:0=NA; 2='1'; 1='0';3:5='0'", as.factor = T)
table(anes2016$Republican)
##
## 0 1
## 2966 1231
# Generation
anes2016$Generation<-recode(anes2016$V161267C, recodes = "1928:1945=NA;1946:1964='BabyBoomer';1965:1980='X';1981:1996='Millenial'; 1997:1998='Z'; 1926:1927=NA; -9:-8=NA", as.factor = T)
table(anes2016$Generation)
##
## BabyBoomer Millenial X Z
## 1473 1051 1046 67
# Total Family Income
anes2016$Income<-recode(anes2016$V161361X, recodes = "-9:-5=NA; 1:14='49.9k or less';15:22='50k to 99.9k';23:28='100k and above'", as.factor = T )
table(anes2016$Income)
##
## 100k and above 49.9k or less 50k to 99.9k
## 988 1809 1272
# College Education
anes2016$CollegeEd<-recode(anes2016$V161270, recodes = "90:95=NA;-9=NA;1:10='0'; 11:16='1'", as.factor = T)
table(anes2016$CollegeEd)
##
## 0 1
## 1991 2236
# Minority Race
anes2016$MinorityRace<-recode(anes2016$V161310X, recodes = "-9=NA; 1='0'; 2:6='1'", as.factor = T)
table(anes2016$MinorityRace)
##
## 0 1
## 3038 1200
# Gender as Woman
anes2016$Woman<-recode(anes2016$V161342, recodes = "-9=NA; 1='0'; 2='1'; 3='0'", as.factor = T)
table(anes2016$Woman)
##
## 0 1
## 1998 2232
sub<-dplyr::select(anes2016,favACA, SelfratedHlth, GovInsur, GovIncSpHC, Democrat, Republican, Generation, Income,CollegeEd, MinorityRace,Woman) %>%
filter(complete.cases(.))
options(survey.lonely.psu = "adjust")
des<-svydesign(nest = TRUE, ids=~anes2016$V160202, strata =~anes2016$V160201, weights =~anes2016$V160101, data=anes2016)
summary(sub)
## favACA SelfratedHlth GovInsur GovIncSpHC Democrat Republican
## 0:1310 Negative: 322 No Plan:1076 Decrease:1124 0:1402 0:1479
## 1: 826 Positive:1814 Plan :1060 Increase:1012 1: 734 1: 657
##
##
## Generation Income CollegeEd MinorityRace Woman
## BabyBoomer:860 100k and above:591 0: 897 0:1557 0:1042
## Millenial :633 49.9k or less :833 1:1239 1: 579 1:1094
## X :606 50k to 99.9k :712
## Z : 37
fit.logit1<-svyglm(favACA~SelfratedHlth+GovInsur+GovIncSpHC,
design= des,
family=binomial)
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
summary(fit.logit1)
##
## Call:
## svyglm(formula = favACA ~ SelfratedHlth + GovInsur + GovIncSpHC,
## design = des, family = binomial)
##
## Survey design:
## svydesign(nest = TRUE, ids = ~anes2016$V160202, strata = ~anes2016$V160201,
## weights = ~anes2016$V160101, data = anes2016)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.3949 0.1678 -14.270 < 2e-16 ***
## SelfratedHlthPositive 0.6435 0.1547 4.160 5.75e-05 ***
## GovInsurPlan 1.5369 0.1142 13.456 < 2e-16 ***
## GovIncSpHCIncrease 1.0817 0.1249 8.658 1.60e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 0.9748056)
##
## Number of Fisher Scoring iterations: 4
fit.logit2<-svyglm(favACA~SelfratedHlth+GovInsur+GovIncSpHC+Democrat+Republican,
design= des,
family=binomial)
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
summary(fit.logit2)
##
## Call:
## svyglm(formula = favACA ~ SelfratedHlth + GovInsur + GovIncSpHC +
## Democrat + Republican, design = des, family = binomial)
##
## Survey design:
## svydesign(nest = TRUE, ids = ~anes2016$V160202, strata = ~anes2016$V160201,
## weights = ~anes2016$V160101, data = anes2016)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.3536 0.2015 -11.678 < 2e-16 ***
## SelfratedHlthPositive 0.7581 0.1710 4.435 1.96e-05 ***
## GovInsurPlan 1.1341 0.1233 9.198 8.69e-16 ***
## GovIncSpHCIncrease 0.7038 0.1346 5.230 6.71e-07 ***
## Democrat1 1.3199 0.1382 9.554 < 2e-16 ***
## Republican1 -1.0094 0.1797 -5.616 1.16e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 0.9705602)
##
## Number of Fisher Scoring iterations: 5
fit.logit3<-svyglm(favACA~SelfratedHlth+GovInsur+GovIncSpHC+Democrat+Republican+Income+Generation+CollegeEd+MinorityRace+Woman,
design= des,
family=binomial)
## Warning in eval(family$initialize): non-integer #successes in a binomial glm!
summary(fit.logit3)
##
## Call:
## svyglm(formula = favACA ~ SelfratedHlth + GovInsur + GovIncSpHC +
## Democrat + Republican + Income + Generation + CollegeEd +
## MinorityRace + Woman, design = des, family = binomial)
##
## Survey design:
## svydesign(nest = TRUE, ids = ~anes2016$V160202, strata = ~anes2016$V160201,
## weights = ~anes2016$V160101, data = anes2016)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.22104 0.27566 -8.057 6.52e-13 ***
## SelfratedHlthPositive 0.49938 0.18217 2.741 0.00706 **
## GovInsurPlan 1.22468 0.14090 8.692 2.18e-14 ***
## GovIncSpHCIncrease 0.67397 0.14970 4.502 1.57e-05 ***
## Democrat1 1.27718 0.14445 8.842 9.68e-15 ***
## Republican1 -0.98706 0.20671 -4.775 5.12e-06 ***
## Income49.9k or less -0.55659 0.18717 -2.974 0.00356 **
## Income50k to 99.9k -0.44910 0.18446 -2.435 0.01638 *
## GenerationMillenial -0.02374 0.16903 -0.140 0.88852
## GenerationX -0.03643 0.16045 -0.227 0.82075
## GenerationZ 0.88798 0.55797 1.591 0.11414
## CollegeEd1 0.41592 0.13466 3.089 0.00250 **
## MinorityRace1 0.52182 0.15833 3.296 0.00129 **
## Woman1 0.03182 0.12181 0.261 0.79437
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 0.9987103)
##
## Number of Fisher Scoring iterations: 5
Model 3 (fit.logit3) has the lowest level of under-dispersion and is deemed the best fitting model for this analysis.