Descriptives for fertility-despair project
1. Load Libraries
2. Import Data (NMFR& Deaths of Despair)
*note we are using mortality data from 2005-2016 and non-marital fertility data from 2010-2021 because we are using a 5-year lag between mortality and fertility
<- read_csv("C:/Users/rlutt/OneDrive/Fall 2023/Advanced Demography/nmfr.csv") nmfr
New names:
Rows: 687 Columns: 6
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," dbl
(6): ...1, STATEFIP, Pop, YEAR, Births, nmfr
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`
<-read_csv("C:/Users/rlutt/OneDrive/Fall 2023/Advanced Demography/popwbirthsunder25.csv") nmfr25under
Rows: 687 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (5): STATEFIP, Pop, YEAR, Births, nmfr
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#DOD Data
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD05.txt",
DOD05 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 160 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD06.txt",
DOD06 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 160 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD07.txt",
DOD07 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 160 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD08.txt",
DOD08 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 163 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD09.txt",
DOD09 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 167 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD10.txt",
DOD10 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 160 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD11.txt",
DOD11 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 160 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD12.txt",
DOD12 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 160 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD13.txt",
DOD13 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 160 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD14.txt",
DOD14 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 162 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD15.txt",
DOD15 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 160 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata/DOD16.txt",
DOD16 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 160 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
3. Clean DOD Data & non-married population data
4. Import Midlife Mortality Data
#mid-life mortality data
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM05.txt",
MLM05 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM06.txt",
MLM06 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM07.txt",
MLM07 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM08.txt",
MLM08 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM09.txt",
MLM09 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM10.txt",
MLM10 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM11.txt",
MLM11 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM12.txt",
MLM12 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM13.txt",
MLM13 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM14.txt",
MLM14 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 88 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM15.txt",
MLM15 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
<- read_delim("C:/Users/rlutt/Downloads/mortalitydata2/MLM16.txt",
MLM16 delim = "\t", escape_double = FALSE,
trim_ws = TRUE)
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 86 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (3): Notes, State, State Code
dbl (4): Deaths, Population, Crude Rate, Age Adjusted Rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
5. Clean Midlife Mortality Data
6. Join mortality data sets together
7. Mortality graphs (DoD & Midlife Mortality)
National DoD from 2005-2016
<- DODtestdf %>% pivot_longer(cols = c(Y05, Y06, Y07, Y08, Y09, Y10, Y11, Y12, Y13, Y14, Y15, Y16), names_to = 'year', values_to = 'DDR')
longDODdata
#calculate averages per year
<-longDODdata%>%
longDODdata2group_by(year)%>%
summarise(mean_DoD = mean(DDR))
#graphic showing variation DoD over the years
library(ggplot2)
ggplot(longDODdata2, aes(x = year, y = mean_DoD))+
geom_point() +
labs(title = "State-level Deaths of Despair Rates", subtitle= "2006 to 2016",
x = "Year",
y = "DDR (per 100,000; age-adjusted)",
caption = "Source: CDC wonder",) +geom_line()
`geom_line()`: Each group consists of only one observation.
ℹ Do you need to adjust the group aesthetic?
National Mid-life all-cause mortality from 2005-2016
<- MLMtestdf %>% pivot_longer(cols=c(Y05, Y06, Y07, Y08, Y09, Y10, Y11, Y12, Y13, Y14, Y15, Y16),names_to = 'year', values_to = 'MLDR')
longMLMdata
#calculate averages per year
<-longMLMdata%>%
longMLMdata2group_by(year)%>%
summarise(mean_MR = mean(MLDR))
#graphic showing variation DoD over the years
library(ggplot2)
ggplot(longMLMdata2, aes(x = year, y = mean_MR))+
geom_point() +
labs(title = "State-level All Cause Mortality Rates", subtitle= "2006 to 2016",
x = "Year",
y = "DDR (per 100,000; age-adjusted)",
caption = "Source: CDC wonder",) + geom_line()
`geom_line()`: Each group consists of only one observation.
ℹ Do you need to adjust the group aesthetic?
State examples of DoD rates from 2005-2016
%>% ggplot(aes(x=year, y=DDR, group=State))+geom_line(aes(color=State))+geom_point(aes(color=State)) longDODdata
<-dplyr::filter(longDODdata, State=="Washington" | State== "West Virginia" | State== "Connecticut" | State== "Alabama"| State== "New Mexico" | State=="Texas")
exmort
%>% ggplot(aes(x=year, y=DDR, group=State))+geom_line()+geom_point()+facet_wrap(~ State) exmort
State examples of Mid-life all-cause mortality rates from 2005-2016
<- MLMtestdf %>% pivot_longer(cols=c(Y05, Y06, Y07, Y08, Y09, Y10, Y11, Y12, Y13, Y14, Y15, Y16),names_to = 'year', values_to = 'MLDR')
longMLMdata
%>% ggplot(aes(x=year, y=MLDR, group=State))+geom_line(aes(color=State))+geom_point(aes(color=State)) longMLMdata
<-dplyr::filter(longMLMdata, State=="Washington" | State== "West Virginia" | State== "Connecticut" | State== "Alabama"| State== "New Mexico" | State=="Texas")
exmortmid
%>% ggplot(aes(x=year, y=MLDR, group=State))+geom_line()+geom_point()+facet_wrap(~State) exmortmid
8. Non-marital fertility graphs (all non-marital fertility and 25 and under non-marital fertility)
National non-marital fertility from 2010-2021
#calculate average per year
<-nmfr%>%
nmfr2group_by(YEAR)%>%
summarise(mean_nmfr = mean(nmfr))
#graphic showing variation in nmfr over the years
library(ggplot2)
ggplot(nmfr2, aes(x = YEAR, y = mean_nmfr)) + scale_x_continuous(breaks=c(2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021))+
geom_point() +
labs(title = "State-level Non-marital fertility", subtitle= "2010 to 2021",
x = "Year",
y = "NMFR (per 1,000)",
caption = "Sources: CDC wonder & American Community Survey",)+geom_line()
Warning: Removed 2 rows containing missing values (`geom_point()`).
Warning: Removed 2 rows containing missing values (`geom_line()`).
National non-marital fertility for women aged 25 and under from 2010-2021
#calculate average per year
<-nmfr25under%>%
popwbirthsunder252group_by(YEAR)%>%
summarise(mean_nmfr = mean(nmfr))
#graphic showing variation in nmfr over the years
library(ggplot2)
ggplot(popwbirthsunder252, aes(x = YEAR, y = mean_nmfr)) + scale_x_continuous(breaks=c(2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021))+
geom_point() +
labs(title = "State-level Non-marital fertility", subtitle= "2010 to 2021",
x = "Year",
y = "NMFR (per 1,000)",
caption = "Sources: CDC wonder & American Community Survey") +geom_line()
Warning: Removed 2 rows containing missing values (`geom_point()`).
Warning: Removed 2 rows containing missing values (`geom_line()`).
State examples of non-marital fertility from 2010-2021
#add a zero to state fips to match state code
$'State Code' <- nmfr$STATEFIP %>% str_pad(2,pad = "0")
nmfr
#merge with mortality data to get state names
<-merge(longDODdata,nmfr, by='State Code')
joined
<-dplyr::filter(joined, State=="Washington" | State== "West Virginia" | State== "Connecticut" | State== "Alabama"| State== "New Mexico" | State=="Texas")
exfert
%>% ggplot(aes(x=YEAR, y=nmfr, group=State))+geom_line()+geom_point()+facet_wrap(~State) exfert
Warning: Removed 72 rows containing missing values (`geom_line()`).
Warning: Removed 72 rows containing missing values (`geom_point()`).
State examples of non-marital fertility for women aged 25 and under from 2010-2021
#add a zero to state fips to match state code
$'State Code' <- nmfr25under$STATEFIP %>% str_pad(2,pad = "0")
nmfr25under
#merge with mortality data to get state names
<-merge(longDODdata,nmfr25under, by='State Code')
joinedunder25
<-dplyr::filter(joinedunder25, State=="Washington" | State== "West Virginia" | State== "Connecticut" | State== "Alabama"| State== "New Mexico" | State=="Texas")
exfertunder25
%>% ggplot(aes(x=YEAR, y=nmfr, group=State))+geom_line()+geom_point()+facet_wrap(~State) exfertunder25
Warning: Removed 72 rows containing missing values (`geom_line()`).
Warning: Removed 72 rows containing missing values (`geom_point()`).