library(haven)
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)
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.1. 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(questionr)
#importing RECS 2015 data
recs2015v2<-read.csv("https://raw.githubusercontent.com/demograf/_Thesis/b9101bf3e4a94c9437557c6a7361e380384ce365/recs2015_public_v2.csv")
Creating a subset without missing values:
myrecs3<-subset(recs2015v2,ZMICRO=1) #has a microwave
myrecs3<-subset(myrecs3,ZOVEN=1) #has an oven
myrecs3<-subset(myrecs3,ZEDUCATION=1) #eductaion question answered
myrecs3<-subset(myrecs3,ZSTOVE=1) #has a stove
myrecs3<-subset(myrecs3,ZOVEN=1) #has an oven
myrecs3<-subset(myrecs3,ZMONEYPY=1) #reported income
Recoding educational attainment and household income:
myrecs3$myedu<-recode(myrecs3$EDUCATION,recodes="
1='No High School';
2='High School';
3='Some College';
4='Bachelors';
5='Masters or PhD'
",as.factor.result=T)
myrecs3$myincome<-recode(myrecs3$MONEYPY,recodes="
1='Less than $20,000';
2='$20,000 - $39,999';
3='$40,000 - $59,999';
4='$60,000 - $79,999';
5='$80,000 - $99,999';
6='$100,000 - $119,999';
7='$120,000 - $139,999';
8='$140,000 or more'
",as.factor.result=T)
Recoding regions:
myrecs3$myregions<-recode(myrecs3$REGIONC,recodes="
1='Northeast';
2='Midwest';
3='South';
4='West';
",as.factor.result=T)
Recoding missing values as zeros for calcuation of cooking methods (-2 indicates “NA”, thus it is effectively a not used case, or 0)
myrecs3$COOKTUSE<-recode(myrecs3$COOKTUSE, recodes = "-2:0=0")
myrecs3$OVENUSE<-recode(myrecs3$OVENUSE, recodes = "-2:0=0")
myrecs3$SEPCOOKTUSE<-recode(myrecs3$SEPCOOKTUSE, recodes = "-2:0=0")
myrecs3$SEPOVENUSE<-recode(myrecs3$SEPOVENUSE, recodes = "-2:0=0")
myrecs3$AMTMICRO<-recode(myrecs3$AMTMICRO, recodes = "-2:0=0")
Calculating the value to be used for binary indicator
myrecs3$mycooks<-myrecs3$COOKTUSE
myrecs3$mycooks<-myrecs3$mycooks+myrecs3$OVENUSE
myrecs3$mycooks<-myrecs3$mycooks+myrecs3$SEPCOOKTUSE
myrecs3$mycooks<-myrecs3$mycooks+myrecs3$SEPOVENUSE
myrecs3$mycooks<-myrecs3$mycooks-myrecs3$AMTMICRO
Recoding as binary variable:
myrecs3$mycooks<-recode(myrecs3$mycooks, recodes="0:396=1;-99:-1=0")
## 1 = prefers cooking with stove / stovetop
## 0 = uses microwave at least as often
In the fillowing code, I use the reference level “South” which is originally the third level in the database which in the following tables will move “West” up to to be indicated as (3).
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:car':
##
## logit
library(nnet)
myfit.multinomial<-vglm(myregions~mycooks+myedu+myincome,multinomial(refLevel='South'),myrecs3,weights=NWEIGHT)
summary(myfit.multinomial)
##
## Call:
## vglm(formula = myregions ~ mycooks + myedu + myincome, family = multinomial(refLevel = "South"),
## data = myrecs3, weights = NWEIGHT)
##
##
## Pearson residuals:
## Min 1Q Median 3Q Max
## log(mu[,1]/mu[,3]) -306.1 -93.03 -43.07 -22.12 605.6
## log(mu[,2]/mu[,3]) -242.4 -85.60 -36.35 -25.22 936.3
## log(mu[,4]/mu[,3]) -291.7 -93.97 -44.42 157.27 665.2
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept):1 -0.3056579 0.0011135 -274.50 <2e-16 ***
## (Intercept):2 -0.5489655 0.0011555 -475.08 <2e-16 ***
## (Intercept):3 -0.1241217 0.0010411 -119.22 <2e-16 ***
## mycooks:1 -0.0971963 0.0004950 -196.37 <2e-16 ***
## mycooks:2 0.2401986 0.0005408 444.16 <2e-16 ***
## mycooks:3 0.0082772 0.0004964 16.68 <2e-16 ***
## myeduHigh School:1 -0.0234642 0.0007810 -30.04 <2e-16 ***
## myeduHigh School:2 -0.1022875 0.0008466 -120.82 <2e-16 ***
## myeduHigh School:3 -0.1072279 0.0008141 -131.71 <2e-16 ***
## myeduMasters or PhD:1 -0.2753652 0.0008788 -313.33 <2e-16 ***
## myeduMasters or PhD:2 -0.1146382 0.0008909 -128.67 <2e-16 ***
## myeduMasters or PhD:3 -0.0871435 0.0008467 -102.92 <2e-16 ***
## myeduNo High School:1 -0.4780624 0.0012126 -394.25 <2e-16 ***
## myeduNo High School:2 -0.1033399 0.0011841 -87.27 <2e-16 ***
## myeduNo High School:3 0.1851114 0.0010896 169.88 <2e-16 ***
## myeduSome College:1 -0.1106547 0.0007152 -154.71 <2e-16 ***
## myeduSome College:2 -0.2876173 0.0007805 -368.51 <2e-16 ***
## myeduSome College:3 0.0154070 0.0007214 21.36 <2e-16 ***
## myincome$120,000 - $139,999:1 0.1099492 0.0015376 71.51 <2e-16 ***
## myincome$120,000 - $139,999:2 0.1651531 0.0015591 105.93 <2e-16 ***
## myincome$120,000 - $139,999:3 -0.2096695 0.0014824 -141.44 <2e-16 ***
## myincome$140,000 or more:1 -0.2667457 0.0013438 -198.50 <2e-16 ***
## myincome$140,000 or more:2 0.0257092 0.0013152 19.55 <2e-16 ***
## myincome$140,000 or more:3 -0.0716111 0.0011896 -60.20 <2e-16 ***
## myincome$20,000 - $39,999:1 -0.0559539 0.0011344 -49.33 <2e-16 ***
## myincome$20,000 - $39,999:2 -0.3676823 0.0011960 -307.41 <2e-16 ***
## myincome$20,000 - $39,999:3 -0.5829528 0.0010734 -543.11 <2e-16 ***
## myincome$40,000 - $59,999:1 -0.1256235 0.0011738 -107.03 <2e-16 ***
## myincome$40,000 - $59,999:2 -0.3970842 0.0012423 -319.63 <2e-16 ***
## myincome$40,000 - $59,999:3 -0.6023029 0.0011167 -539.34 <2e-16 ***
## myincome$60,000 - $79,999:1 0.2281068 0.0012021 189.75 <2e-16 ***
## myincome$60,000 - $79,999:2 -0.0133934 0.0012641 -10.60 <2e-16 ***
## myincome$60,000 - $79,999:3 -0.2107975 0.0011430 -184.42 <2e-16 ***
## myincome$80,000 - $99,999:1 0.1131263 0.0013051 86.68 <2e-16 ***
## myincome$80,000 - $99,999:2 -0.2206130 0.0014042 -157.11 <2e-16 ***
## myincome$80,000 - $99,999:3 -0.1967661 0.0012389 -158.82 <2e-16 ***
## myincomeLess than $20,000:1 -0.2228518 0.0011969 -186.19 <2e-16 ***
## myincomeLess than $20,000:2 -0.2233457 0.0012370 -180.55 <2e-16 ***
## myincomeLess than $20,000:3 -0.5192862 0.0011199 -463.69 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Number of linear predictors: 3
##
## Names of linear predictors:
## log(mu[,1]/mu[,3]), log(mu[,2]/mu[,3]), log(mu[,4]/mu[,3])
##
## Residual deviance: 315222343 on 17019 degrees of freedom
##
## Log-likelihood: -157611171 on 17019 degrees of freedom
##
## Number of iterations: 4
##
## No Hauck-Donner effect found in any of the estimates
##
## Reference group is level 3 of the response
library(VGAM)
library(nnet)
myfit.multinomial<-vglm(myregions~mycooks+myedu+myincome,multinomial(refLevel='South'),myrecs3,weights=NWEIGHT)
summary(myfit.multinomial)
##
## Call:
## vglm(formula = myregions ~ mycooks + myedu + myincome, family = multinomial(refLevel = "South"),
## data = myrecs3, weights = NWEIGHT)
##
##
## Pearson residuals:
## Min 1Q Median 3Q Max
## log(mu[,1]/mu[,3]) -306.1 -93.03 -43.07 -22.12 605.6
## log(mu[,2]/mu[,3]) -242.4 -85.60 -36.35 -25.22 936.3
## log(mu[,4]/mu[,3]) -291.7 -93.97 -44.42 157.27 665.2
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept):1 -0.3056579 0.0011135 -274.50 <2e-16 ***
## (Intercept):2 -0.5489655 0.0011555 -475.08 <2e-16 ***
## (Intercept):3 -0.1241217 0.0010411 -119.22 <2e-16 ***
## mycooks:1 -0.0971963 0.0004950 -196.37 <2e-16 ***
## mycooks:2 0.2401986 0.0005408 444.16 <2e-16 ***
## mycooks:3 0.0082772 0.0004964 16.68 <2e-16 ***
## myeduHigh School:1 -0.0234642 0.0007810 -30.04 <2e-16 ***
## myeduHigh School:2 -0.1022875 0.0008466 -120.82 <2e-16 ***
## myeduHigh School:3 -0.1072279 0.0008141 -131.71 <2e-16 ***
## myeduMasters or PhD:1 -0.2753652 0.0008788 -313.33 <2e-16 ***
## myeduMasters or PhD:2 -0.1146382 0.0008909 -128.67 <2e-16 ***
## myeduMasters or PhD:3 -0.0871435 0.0008467 -102.92 <2e-16 ***
## myeduNo High School:1 -0.4780624 0.0012126 -394.25 <2e-16 ***
## myeduNo High School:2 -0.1033399 0.0011841 -87.27 <2e-16 ***
## myeduNo High School:3 0.1851114 0.0010896 169.88 <2e-16 ***
## myeduSome College:1 -0.1106547 0.0007152 -154.71 <2e-16 ***
## myeduSome College:2 -0.2876173 0.0007805 -368.51 <2e-16 ***
## myeduSome College:3 0.0154070 0.0007214 21.36 <2e-16 ***
## myincome$120,000 - $139,999:1 0.1099492 0.0015376 71.51 <2e-16 ***
## myincome$120,000 - $139,999:2 0.1651531 0.0015591 105.93 <2e-16 ***
## myincome$120,000 - $139,999:3 -0.2096695 0.0014824 -141.44 <2e-16 ***
## myincome$140,000 or more:1 -0.2667457 0.0013438 -198.50 <2e-16 ***
## myincome$140,000 or more:2 0.0257092 0.0013152 19.55 <2e-16 ***
## myincome$140,000 or more:3 -0.0716111 0.0011896 -60.20 <2e-16 ***
## myincome$20,000 - $39,999:1 -0.0559539 0.0011344 -49.33 <2e-16 ***
## myincome$20,000 - $39,999:2 -0.3676823 0.0011960 -307.41 <2e-16 ***
## myincome$20,000 - $39,999:3 -0.5829528 0.0010734 -543.11 <2e-16 ***
## myincome$40,000 - $59,999:1 -0.1256235 0.0011738 -107.03 <2e-16 ***
## myincome$40,000 - $59,999:2 -0.3970842 0.0012423 -319.63 <2e-16 ***
## myincome$40,000 - $59,999:3 -0.6023029 0.0011167 -539.34 <2e-16 ***
## myincome$60,000 - $79,999:1 0.2281068 0.0012021 189.75 <2e-16 ***
## myincome$60,000 - $79,999:2 -0.0133934 0.0012641 -10.60 <2e-16 ***
## myincome$60,000 - $79,999:3 -0.2107975 0.0011430 -184.42 <2e-16 ***
## myincome$80,000 - $99,999:1 0.1131263 0.0013051 86.68 <2e-16 ***
## myincome$80,000 - $99,999:2 -0.2206130 0.0014042 -157.11 <2e-16 ***
## myincome$80,000 - $99,999:3 -0.1967661 0.0012389 -158.82 <2e-16 ***
## myincomeLess than $20,000:1 -0.2228518 0.0011969 -186.19 <2e-16 ***
## myincomeLess than $20,000:2 -0.2233457 0.0012370 -180.55 <2e-16 ***
## myincomeLess than $20,000:3 -0.5192862 0.0011199 -463.69 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Number of linear predictors: 3
##
## Names of linear predictors:
## log(mu[,1]/mu[,3]), log(mu[,2]/mu[,3]), log(mu[,4]/mu[,3])
##
## Residual deviance: 315222343 on 17019 degrees of freedom
##
## Log-likelihood: -157611171 on 17019 degrees of freedom
##
## Number of iterations: 4
##
## No Hauck-Donner effect found in any of the estimates
##
## Reference group is level 3 of the response
Coefficients, rounded to the third decimal:
round(exp(coef(myfit.multinomial)),3)
## (Intercept):1 (Intercept):2
## 0.737 0.578
## (Intercept):3 mycooks:1
## 0.883 0.907
## mycooks:2 mycooks:3
## 1.272 1.008
## myeduHigh School:1 myeduHigh School:2
## 0.977 0.903
## myeduHigh School:3 myeduMasters or PhD:1
## 0.898 0.759
## myeduMasters or PhD:2 myeduMasters or PhD:3
## 0.892 0.917
## myeduNo High School:1 myeduNo High School:2
## 0.620 0.902
## myeduNo High School:3 myeduSome College:1
## 1.203 0.895
## myeduSome College:2 myeduSome College:3
## 0.750 1.016
## myincome$120,000 - $139,999:1 myincome$120,000 - $139,999:2
## 1.116 1.180
## myincome$120,000 - $139,999:3 myincome$140,000 or more:1
## 0.811 0.766
## myincome$140,000 or more:2 myincome$140,000 or more:3
## 1.026 0.931
## myincome$20,000 - $39,999:1 myincome$20,000 - $39,999:2
## 0.946 0.692
## myincome$20,000 - $39,999:3 myincome$40,000 - $59,999:1
## 0.558 0.882
## myincome$40,000 - $59,999:2 myincome$40,000 - $59,999:3
## 0.672 0.548
## myincome$60,000 - $79,999:1 myincome$60,000 - $79,999:2
## 1.256 0.987
## myincome$60,000 - $79,999:3 myincome$80,000 - $99,999:1
## 0.810 1.120
## myincome$80,000 - $99,999:2 myincome$80,000 - $99,999:3
## 0.802 0.821
## myincomeLess than $20,000:1 myincomeLess than $20,000:2
## 0.800 0.800
## myincomeLess than $20,000:3
## 0.595
Confidence Intervals, rounded to the third decimal.
All values are compared to the Census Region South with the following order: 1: Northeast 2: Midwest 3: West
Values show the ratio of preference of sove / oven use in relation to microwave use. A value below one means that, compared to the region South, the group prefers microwave use. A value of 1 and above means that, compared to the region South, the group prefers oven / stove top use:
round(exp(confint(myfit.multinomial)),3)
## 2.5 % 97.5 %
## (Intercept):1 0.735 0.738
## (Intercept):2 0.576 0.579
## (Intercept):3 0.881 0.885
## mycooks:1 0.906 0.908
## mycooks:2 1.270 1.273
## mycooks:3 1.007 1.009
## myeduHigh School:1 0.975 0.978
## myeduHigh School:2 0.901 0.904
## myeduHigh School:3 0.897 0.900
## myeduMasters or PhD:1 0.758 0.761
## myeduMasters or PhD:2 0.890 0.893
## myeduMasters or PhD:3 0.915 0.918
## myeduNo High School:1 0.619 0.621
## myeduNo High School:2 0.900 0.904
## myeduNo High School:3 1.201 1.206
## myeduSome College:1 0.894 0.897
## myeduSome College:2 0.749 0.751
## myeduSome College:3 1.014 1.017
## myincome$120,000 - $139,999:1 1.113 1.120
## myincome$120,000 - $139,999:2 1.176 1.183
## myincome$120,000 - $139,999:3 0.808 0.813
## myincome$140,000 or more:1 0.764 0.768
## myincome$140,000 or more:2 1.023 1.029
## myincome$140,000 or more:3 0.929 0.933
## myincome$20,000 - $39,999:1 0.943 0.948
## myincome$20,000 - $39,999:2 0.691 0.694
## myincome$20,000 - $39,999:3 0.557 0.559
## myincome$40,000 - $59,999:1 0.880 0.884
## myincome$40,000 - $59,999:2 0.671 0.674
## myincome$40,000 - $59,999:3 0.546 0.549
## myincome$60,000 - $79,999:1 1.253 1.259
## myincome$60,000 - $79,999:2 0.984 0.989
## myincome$60,000 - $79,999:3 0.808 0.812
## myincome$80,000 - $99,999:1 1.117 1.123
## myincome$80,000 - $99,999:2 0.800 0.804
## myincome$80,000 - $99,999:3 0.819 0.823
## myincomeLess than $20,000:1 0.798 0.802
## myincomeLess than $20,000:2 0.798 0.802
## myincomeLess than $20,000:3 0.594 0.596
stargazer(exp(cbind(OR=coef(myfit.multinomial),confint(myfit.multinomial))),type="text",style="demography", title="Stove Top Use Preference by Region")
##
## Stove Top Use Preference by Region
## ----------------------------------------
## OR 2.5 % 97.5 %
## ----------------------------------------
## (Intercept):1 0.737 0.735 0.738
## (Intercept):2 0.578 0.576 0.579
## (Intercept):3 0.883 0.881 0.885
## mycooks:1 0.907 0.906 0.908
## mycooks:2 1.272 1.270 1.273
## mycooks:3 1.008 1.007 1.009
## myeduHigh School:1 0.977 0.975 0.978
## myeduHigh School:2 0.903 0.901 0.904
## myeduHigh School:3 0.898 0.897 0.900
## myeduMasters or PhD:1 0.759 0.758 0.761
## myeduMasters or PhD:2 0.892 0.890 0.893
## myeduMasters or PhD:3 0.917 0.915 0.918
## myeduNo High School:1 0.620 0.619 0.621
## myeduNo High School:2 0.902 0.900 0.904
## myeduNo High School:3 1.203 1.201 1.206
## myeduSome College:1 0.895 0.894 0.897
## myeduSome College:2 0.750 0.749 0.751
## myeduSome College:3 1.016 1.014 1.017
## myincome- 1.116 1.113 1.120
## myincome- 1.180 1.176 1.183
## myincome- 0.811 0.808 0.813
## myincomeor more:1 0.766 0.764 0.768
## myincomeor more:2 1.026 1.023 1.029
## myincomeor more:3 0.931 0.929 0.933
## myincome- 0.946 0.943 0.948
## myincome- 0.692 0.691 0.694
## myincome- 0.558 0.557 0.559
## myincome- 0.882 0.880 0.884
## myincome- 0.672 0.671 0.674
## myincome- 0.548 0.546 0.549
## myincome- 1.256 1.253 1.259
## myincome- 0.987 0.984 0.989
## myincome- 0.810 0.808 0.812
## myincome- 1.120 1.117 1.123
## myincome- 0.802 0.800 0.804
## myincome- 0.821 0.819 0.823
## myincomeLess than 0.800 0.798 0.802
## myincomeLess than 0.800 0.798 0.802
## myincomeLess than 0.595 0.594 0.596
## ----------------------------------------