#1. Binary Outcome Variable The binary outcome variable is the presence of just one or more than one unique substance reported. To recode this varibale I used the ifelse function to recode 1 to 0 since a response of 1 means there was NOT more than 1 unique drug reported. Then I recoded all other values to 1 since these values indicated more than 1 unique drug reported.
#2. Research Question Are there differences in the presence of more than substance in various demographic groups?
#3. Predictor Variables The predictor variables that I will look at are age and sex. In this data set age is categorized into 11 groups.
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(questionr)
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(forcats)
load("~/Documents/Stats2-Dem7283 /Stats2/ICPSR_34565-2/DS0001/34565-0001-Data.rda")
dawn2011 <- da34565.0001
#number of substances
dawn2011$morethanonesub <- ifelse(dawn2011$NUMSUBS==1,0,1)
#age
dawn2011$age <- Recode(dawn2011$AGECAT, recodes= "-8:NA")
dawn2011 <- dawn2011 %>%
filter(is.na(age)==F,
SEX!= -8)
#unweighted
table(dawn2011$morethanonesub, dawn2011$SEX)
##
## (1) MALE:(1) (2) FEMALE:(2)
## 0 71104 75951
## 1 47969 34053
table(dawn2011$morethanonesub, dawn2011$age)
##
## (01) AGE 5 OR YOUNGER:(1) (02) 6 TO 11:(2) (03) 12 TO 17:(3)
## 0 7882 1815 8739
## 1 857 287 3186
##
## (04) 18 TO 20:(4) (05) 21 TO 24:(5) (06) 25 TO 29:(6) (07) 30 TO 34:(7)
## 0 12245 10426 12605 11243
## 1 4773 7837 9428 8701
##
## (08) 35 TO 44:(8) (09) 45 TO 54:(9) (10) 55 TO 64:(10)
## 0 20580 22776 15968
## 1 16327 17018 7860
##
## (11) AGE 65 OR OLDER:(11)
## 0 22776
## 1 5748
100*prop.table(table(dawn2011$morethanonesub, dawn2011$SEX), margin = 2)
##
## (1) MALE:(1) (2) FEMALE:(2)
## 0 59.71463 69.04385
## 1 40.28537 30.95615
100*prop.table(table(dawn2011$morethanonesub, dawn2011$age))
##
## (01) AGE 5 OR YOUNGER:(1) (02) 6 TO 11:(2) (03) 12 TO 17:(3)
## 0 3.4407645 0.7923100 3.8148745
## 1 0.3741100 0.1252854 1.3907987
##
## (04) 18 TO 20:(4) (05) 21 TO 24:(5) (06) 25 TO 29:(6) (07) 30 TO 34:(7)
## 0 5.3453642 4.5513081 5.5025166 4.9079567
## 1 2.0835789 3.4211204 4.1156467 3.7982862
##
## (08) 35 TO 44:(8) (09) 45 TO 54:(9) (10) 55 TO 64:(10)
## 0 8.9838788 9.9425084 6.9705819
## 1 7.1272978 7.4289431 3.4311607
##
## (11) AGE 65 OR OLDER:(11)
## 0 9.9425084
## 1 2.5092000
chisq.test(table(dawn2011$SEX, dawn2011$morethanonesub))
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: table(dawn2011$SEX, dawn2011$morethanonesub)
## X-squared = 2164.7, df = 1, p-value < 2.2e-16
chisq.test(table(dawn2011$age, dawn2011$morethanonesub))
##
## Pearson's Chi-squared test
##
## data: table(dawn2011$age, dawn2011$morethanonesub)
## X-squared = 10397, df = 10, p-value < 2.2e-16
library(srvyr)
##
## Attaching package: 'srvyr'
## The following object is masked from 'package:stats':
##
## filter
options(scipen = 999)
options(survey.lonely.psu = "adjust")
des <- svydesign(ids = ~PSU,
strata = ~STRATA,
weights = ~CASEWGT,
nest = TRUE,
data=dawn2011)
des
## Stratified 1 - level Cluster Sampling design (with replacement)
## With (233) clusters.
## svydesign(ids = ~PSU, strata = ~STRATA, weights = ~CASEWGT, nest = TRUE,
## data = dawn2011)
#counts
cat<-wtd.table(dawn2011$morethanonesub, dawn2011$SEX, weights = dawn2011$CASEWGT)
cat
## (1) MALE:(1) (2) FEMALE:(2)
## 0 1504733.6 1854505.8
## 1 907779.1 797706.2
prop.table(cat, margin = 2)
## (1) MALE:(1) (2) FEMALE:(2)
## 0 0.6237205 0.6992298
## 1 0.3762795 0.3007702
agecnt <- wtd.table(dawn2011$morethanonesub, dawn2011$age, weights = dawn2011$CASEWGT)
agecnt
## (01) AGE 5 OR YOUNGER:(1) (02) 6 TO 11:(2) (03) 12 TO 17:(3)
## 0 261070.98 60111.10 202697.18
## 1 30352.72 10668.83 80930.53
## (04) 18 TO 20:(4) (05) 21 TO 24:(5) (06) 25 TO 29:(6) (07) 30 TO 34:(7)
## 0 230912.65 226291.87 267742.83 242249.24
## 1 103178.49 185266.15 207129.90 193060.66
## (08) 35 TO 44:(8) (09) 45 TO 54:(9) (10) 55 TO 64:(10)
## 0 436986.53 472505.32 360639.43
## 1 286232.43 300543.83 155796.53
## (11) AGE 65 OR OLDER:(11)
## 0 598032.33
## 1 152325.26
prop.table(agecnt, margin = 2)
## (01) AGE 5 OR YOUNGER:(1) (02) 6 TO 11:(2) (03) 12 TO 17:(3)
## 0 0.8958468 0.8492675 0.7146593
## 1 0.1041532 0.1507325 0.2853407
## (04) 18 TO 20:(4) (05) 21 TO 24:(5) (06) 25 TO 29:(6) (07) 30 TO 34:(7)
## 0 0.6911666 0.5498420 0.5638202 0.5564984
## 1 0.3088334 0.4501580 0.4361798 0.4435016
## (08) 35 TO 44:(8) (09) 45 TO 54:(9) (10) 55 TO 64:(10)
## 0 0.6042244 0.6112229 0.6983236
## 1 0.3957756 0.3887771 0.3016764
## (11) AGE 65 OR OLDER:(11)
## 0 0.7969964
## 1 0.2030036
svychisq(~morethanonesub+age, design = des)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~morethanonesub + age, design = des)
## F = 85.242, ndf = 3.2842, ddf = 597.7269, p-value < 0.00000000000000022
svychisq(~morethanonesub+SEX, design = des)
##
## Pearson's X^2: Rao & Scott adjustment
##
## data: svychisq(~morethanonesub + SEX, design = des)
## F = 135.42, ndf = 1, ddf = 182, p-value < 0.00000000000000022
citytab <- svyby(~morethanonesub,
~METRO,
design = des,
FUN = svymean,
na.rm=TRUE)
knitr::kable(citytab,
type="html",
digits=3,
caption = "More than one Substance MSAs")
| METRO | morethanonesub | se | |
|---|---|---|---|
| (01) BOSTON-CAMBRIDGE-QUINCY, MA-NH MSA:(1) | (01) BOSTON-CAMBRIDGE-QUINCY, MA-NH MSA:(1) | 0.352 | 0.014 |
| (02) NEW YORK CITY - 5 BUROUGHS (PART OF NEW YORK- NEWARK-EDISON, NY-NJ-PA MSA):(2) | (02) NEW YORK CITY - 5 BUROUGHS (PART OF NEW YORK- NEWARK-EDISON, NY-NJ-PA MSA):(2) | 0.395 | 0.022 |
| (03) CHICAGO-NAPERVILLE-JOLIET, IL-IN-WI MSA:(3) | (03) CHICAGO-NAPERVILLE-JOLIET, IL-IN-WI MSA:(3) | 0.316 | 0.013 |
| (04) DETROIT-WARREN-LIVONIA, MI MSA:(4) | (04) DETROIT-WARREN-LIVONIA, MI MSA:(4) | 0.328 | 0.027 |
| (05) MINNEAPOLIS-ST. PAUL-BLOOMINGTON, MN-WI MSA:(5) | (05) MINNEAPOLIS-ST. PAUL-BLOOMINGTON, MN-WI MSA:(5) | 0.382 | 0.015 |
| (06) FORT LAUNDERALE DIVISION OF MIAMI-FORT LAUDERDALE, FL MSA:(6) | (06) FORT LAUNDERALE DIVISION OF MIAMI-FORT LAUDERDALE, FL MSA:(6) | 0.351 | 0.049 |
| (07) DADE COUNTY DIVISION OF MIAMI-FORT LAUDERDALE, FL MSA:(7) | (07) DADE COUNTY DIVISION OF MIAMI-FORT LAUDERDALE, FL MSA:(7) | 0.359 | 0.085 |
| (08) HOUSTON-BAYTOWN-SUGAR LAND, TX MSA:(8) | (08) HOUSTON-BAYTOWN-SUGAR LAND, TX MSA:(8) | 0.372 | 0.038 |
| (09) DENVER-AURORA, CO MSA:(9) | (09) DENVER-AURORA, CO MSA:(9) | 0.354 | 0.012 |
| (10) PHOENIX-MESA-SCOTTSDALE, AZ MSA:(10) | (10) PHOENIX-MESA-SCOTTSDALE, AZ MSA:(10) | 0.361 | 0.025 |
| (11) OAKLAND DIVISION OF SAN FRANCISCO-OAKLAND-FREMONT, CA MSA:(11) | (11) OAKLAND DIVISION OF SAN FRANCISCO-OAKLAND-FREMONT, CA MSA:(11) | 0.335 | 0.017 |
| (12) SAN FRANCISCO DIVISION OF SAN FRANCISCO-OAKLAND-FREMONT, CA MSA:(12) | (12) SAN FRANCISCO DIVISION OF SAN FRANCISCO-OAKLAND-FREMONT, CA MSA:(12) | 0.281 | 0.025 |
| (13) SEATTLE-TACOMA-BELLEVUE, WA MSA:(13) | (13) SEATTLE-TACOMA-BELLEVUE, WA MSA:(13) | 0.336 | 0.016 |
| (14) ALL OTHER LOCATIONS:(14) | (14) ALL OTHER LOCATIONS:(14) | 0.334 | 0.021 |
There are differences when using the survey weights.