Yingfa Gao
2023-12-07
Income inequality and wage disparities are critical issues in contemporary socio-economic discussions. This study focuses on dissecting these disparities, with a particular emphasis on educational accessibility, the gender pay gap, and ethnic wage differentials. The objective is to analyze and understand the dynamics of wage variations across different demographics, specifically examining the interplay between education, gender, and income.
The primary dataset for this analysis includes variables such as education levels, gender, and ethnicity. Key variables include:
Wages by education level (less than high school, high school, some college, bachelor’s degree, advanced degree).
Source: https://www.epi.org/data/#?subject=wage-education
The dataset is accompanied by comprehensive documentation, which includes a data dictionary for clarity on the variables used.
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.4 ✔ purrr 1.0.2
## ✔ tibble 3.2.1 ✔ dplyr 1.1.2
## ✔ tidyr 1.3.0 ✔ stringr 1.5.0
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
##
## Attaching package: 'lubridate'
##
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(dplyr)
library(ggplot2)
library(tidyr)
library(readr)
# Load and Preview Data
wages <- read_csv("~/Desktop/Programming Language/R/csc530/Final Project/EPI Data Library - Wages by education.csv")## Rows: 50 Columns: 31
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (30): Less than HS, High school, Some college, Bachelor's degree, Advanc...
## dbl (1): Date
##
## ℹ 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.
## # A tibble: 6 × 31
## Date `Less than HS` `High school` `Some college` `Bachelor's degree`
## <dbl> <chr> <chr> <chr> <chr>
## 1 2022 $16.52 $21.94 $24.81 $41.60
## 2 2021 $16.74 $22.28 $24.92 $41.32
## 3 2020 $17.02 $22.70 $25.44 $41.65
## 4 2019 $16.11 $21.64 $24.00 $39.61
## 5 2018 $15.94 $21.50 $23.70 $38.87
## 6 2017 $15.92 $21.26 $23.31 $38.65
## # ℹ 26 more variables: `Advanced degree` <chr>, `Less than HS Share` <chr>,
## # `High school Share` <chr>, `Some college Share` <chr>,
## # `Bachelor's degree Share` <chr>, `Advanced degree Share` <chr>,
## # `Men Less than HS` <chr>, `Men High school` <chr>,
## # `Men Some college` <chr>, `Men Bachelor's degree` <chr>,
## # `Men Advanced degree` <chr>, `Men Less than HS Share` <chr>,
## # `Men High school Share` <chr>, `Men Some college Share` <chr>, …
## # A tibble: 1 × 0
## spc_tbl_ [50 × 31] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ Date : num [1:50] 2022 2021 2020 2019 2018 ...
## $ Less than HS : chr [1:50] "$16.52" "$16.74" "$17.02" "$16.11" ...
## $ High school : chr [1:50] "$21.94" "$22.28" "$22.70" "$21.64" ...
## $ Some college : chr [1:50] "$24.81" "$24.92" "$25.44" "$24.00" ...
## $ Bachelor's degree : chr [1:50] "$41.60" "$41.32" "$41.65" "$39.61" ...
## $ Advanced degree : chr [1:50] "$53.22" "$53.45" "$53.74" "$51.57" ...
## $ Less than HS Share : chr [1:50] "7.6%" "7.5%" "7.2%" "8.0%" ...
## $ High school Share : chr [1:50] "26.0%" "25.4%" "25.2%" "26.1%" ...
## $ Some college Share : chr [1:50] "25.9%" "26.6%" "27.1%" "27.7%" ...
## $ Bachelor's degree Share : chr [1:50] "25.6%" "25.5%" "25.5%" "24.3%" ...
## $ Advanced degree Share : chr [1:50] "15.0%" "14.9%" "15.0%" "13.8%" ...
## $ Men Less than HS : chr [1:50] "$17.99" "$18.34" "$18.76" "$17.55" ...
## $ Men High school : chr [1:50] "$24.08" "$24.36" "$25.09" "$23.99" ...
## $ Men Some college : chr [1:50] "$27.96" "$27.96" "$28.55" "$26.99" ...
## $ Men Bachelor's degree : chr [1:50] "$49.01" "$47.83" "$48.15" "$45.74" ...
## $ Men Advanced degree : chr [1:50] "$63.51" "$63.52" "$62.70" "$59.93" ...
## $ Men Less than HS Share : chr [1:50] "8.7%" "8.7%" "8.4%" "9.3%" ...
## $ Men High school Share : chr [1:50] "29.2%" "28.7%" "28.3%" "28.9%" ...
## $ Men Some college Share : chr [1:50] "24.4%" "25.3%" "26.0%" "26.4%" ...
## $ Men Bachelor's degree Share : chr [1:50] "24.3%" "24.1%" "24.1%" "22.9%" ...
## $ Men Advanced degree Share : chr [1:50] "13.4%" "13.3%" "13.4%" "12.5%" ...
## $ Women Less than HS : chr [1:50] "$14.33" "$14.36" "$14.40" "$13.96" ...
## $ Women High school : chr [1:50] "$18.93" "$19.36" "$19.35" "$18.48" ...
## $ Women Some college : chr [1:50] "$21.76" "$21.97" "$22.35" "$21.09" ...
## $ Women Bachelor's degree : chr [1:50] "$34.39" "$35.08" "$35.41" "$33.80" ...
## $ Women Advanced degree : chr [1:50] "$44.34" "$44.80" "$46.04" "$44.22" ...
## $ Women Less than HS Share : chr [1:50] "6.3%" "6.3%" "6.0%" "6.7%" ...
## $ Women High school Share : chr [1:50] "22.5%" "22.0%" "21.8%" "23.1%" ...
## $ Women Some college Share : chr [1:50] "27.4%" "28.0%" "28.2%" "29.2%" ...
## $ Women Bachelor's degree Share: chr [1:50] "27.0%" "27.1%" "27.1%" "25.9%" ...
## $ Women Advanced degree Share : chr [1:50] "16.8%" "16.7%" "16.8%" "15.3%" ...
## - attr(*, "spec")=
## .. cols(
## .. Date = col_double(),
## .. `Less than HS` = col_character(),
## .. `High school` = col_character(),
## .. `Some college` = col_character(),
## .. `Bachelor's degree` = col_character(),
## .. `Advanced degree` = col_character(),
## .. `Less than HS Share` = col_character(),
## .. `High school Share` = col_character(),
## .. `Some college Share` = col_character(),
## .. `Bachelor's degree Share` = col_character(),
## .. `Advanced degree Share` = col_character(),
## .. `Men Less than HS` = col_character(),
## .. `Men High school` = col_character(),
## .. `Men Some college` = col_character(),
## .. `Men Bachelor's degree` = col_character(),
## .. `Men Advanced degree` = col_character(),
## .. `Men Less than HS Share` = col_character(),
## .. `Men High school Share` = col_character(),
## .. `Men Some college Share` = col_character(),
## .. `Men Bachelor's degree Share` = col_character(),
## .. `Men Advanced degree Share` = col_character(),
## .. `Women Less than HS` = col_character(),
## .. `Women High school` = col_character(),
## .. `Women Some college` = col_character(),
## .. `Women Bachelor's degree` = col_character(),
## .. `Women Advanced degree` = col_character(),
## .. `Women Less than HS Share` = col_character(),
## .. `Women High school Share` = col_character(),
## .. `Women Some college Share` = col_character(),
## .. `Women Bachelor's degree Share` = col_character(),
## .. `Women Advanced degree Share` = col_character()
## .. )
## - attr(*, "problems")=<externalptr>
## [1] "Date" "Less than HS"
## [3] "High school" "Some college"
## [5] "Bachelor's degree" "Advanced degree"
## [7] "Less than HS Share" "High school Share"
## [9] "Some college Share" "Bachelor's degree Share"
## [11] "Advanced degree Share" "Men Less than HS"
## [13] "Men High school" "Men Some college"
## [15] "Men Bachelor's degree" "Men Advanced degree"
## [17] "Men Less than HS Share" "Men High school Share"
## [19] "Men Some college Share" "Men Bachelor's degree Share"
## [21] "Men Advanced degree Share" "Women Less than HS"
## [23] "Women High school" "Women Some college"
## [25] "Women Bachelor's degree" "Women Advanced degree"
## [27] "Women Less than HS Share" "Women High school Share"
## [29] "Women Some college Share" "Women Bachelor's degree Share"
## [31] "Women Advanced degree Share"
Describe the steps you took to get from your original dataset to the final dataset you used for your analysis. Include the R code in chunks.
# Data Transformation
wages <- wages %>%
mutate(across(where(is.character), na_if, "")) %>%
mutate(across(where(is.character), readr::parse_number))## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `across(where(is.character), na_if, "")`.
## Caused by warning:
## ! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
## Supply arguments directly to `.fns` through an anonymous function instead.
##
## # Previously
## across(a:b, mean, na.rm = TRUE)
##
## # Now
## across(a:b, \(x) mean(x, na.rm = TRUE))
# Date Formatting
wages$Date <- as.Date(as.character(wages$Date), format = "%Y")
# Outlier Examination
summary(wages)## Date Less than HS High school Some college
## Min. :1973-12-06 Min. :13.95 Min. :19.62 Min. :22.04
## 1st Qu.:1986-03-07 1st Qu.:14.88 1st Qu.:20.39 1st Qu.:22.55
## Median :1998-06-06 Median :15.34 Median :20.86 Median :23.18
## Mean :1998-06-06 Mean :15.70 Mean :20.88 Mean :23.22
## 3rd Qu.:2010-09-05 3rd Qu.:16.50 3rd Qu.:21.48 3rd Qu.:23.70
## Max. :2022-12-06 Max. :18.06 Max. :22.70 Max. :25.44
## Bachelor's degree Advanced degree Less than HS Share High school Share
## Min. :30.04 Min. :35.32 Min. : 7.200 Min. :25.20
## 1st Qu.:31.88 1st Qu.:38.76 1st Qu.: 9.625 1st Qu.:28.23
## Median :34.20 Median :44.09 Median :13.050 Median :32.20
## Mean :34.77 Mean :43.90 Mean :14.800 Mean :32.07
## 3rd Qu.:37.12 3rd Qu.:47.56 3rd Qu.:17.350 3rd Qu.:36.27
## Max. :41.65 Max. :53.74 Max. :31.600 Max. :37.40
## Some college Share Bachelor's degree Share Advanced degree Share
## Min. :17.60 Min. :10.30 Min. : 4.200
## 1st Qu.:24.18 1st Qu.:14.75 1st Qu.: 6.625
## Median :28.25 Median :17.65 Median : 8.100
## Mean :26.42 Mean :17.84 Mean : 8.868
## 3rd Qu.:29.18 3rd Qu.:21.43 3rd Qu.:11.025
## Max. :30.00 Max. :25.60 Max. :15.000
## Men Less than HS Men High school Men Some college Men Bachelor's degree
## Min. :15.39 Min. :22.11 Min. :24.78 Min. :35.16
## 1st Qu.:16.25 1st Qu.:22.95 1st Qu.:25.80 1st Qu.:36.60
## Median :16.91 Median :23.70 Median :26.36 Median :39.48
## Mean :17.57 Mean :23.83 Mean :26.33 Mean :39.99
## 3rd Qu.:18.61 3rd Qu.:24.31 3rd Qu.:27.01 3rd Qu.:42.34
## Max. :21.18 Max. :26.90 Max. :28.55 Max. :49.01
## Men Advanced degree Men Less than HS Share Men High school Share
## Min. :38.72 Min. : 8.40 Min. :28.30
## 1st Qu.:43.07 1st Qu.:11.40 1st Qu.:29.93
## Median :48.94 Median :14.90 Median :32.10
## Mean :49.43 Mean :16.60 Mean :31.80
## 3rd Qu.:54.51 3rd Qu.:19.32 3rd Qu.:33.70
## Max. :63.52 Max. :33.40 Max. :34.90
## Men Some college Share Men Bachelor's degree Share Men Advanced degree Share
## Min. :18.30 Min. :10.50 Min. : 5.200
## 1st Qu.:23.10 1st Qu.:15.10 1st Qu.: 7.800
## Median :26.50 Median :17.35 Median : 8.550
## Mean :24.96 Mean :17.50 Mean : 9.138
## 3rd Qu.:27.07 3rd Qu.:20.35 3rd Qu.:10.850
## Max. :27.90 Max. :24.30 Max. :13.400
## Women Less than HS Women High school Women Some college
## Min. :11.75 Min. :16.45 Min. :17.91
## 1st Qu.:12.50 1st Qu.:16.89 1st Qu.:18.78
## Median :12.81 Median :17.37 Median :19.98
## Mean :12.85 Mean :17.57 Mean :19.94
## 3rd Qu.:13.08 3rd Qu.:18.32 3rd Qu.:21.07
## Max. :14.40 Max. :19.36 Max. :22.35
## Women Bachelor's degree Women Advanced degree Women Less than HS Share
## Min. :22.94 Min. :28.47 Min. : 6.00
## 1st Qu.:25.46 1st Qu.:32.28 1st Qu.: 7.80
## Median :29.43 Median :38.34 Median :11.10
## Mean :28.93 Mean :36.98 Mean :12.75
## 3rd Qu.:31.98 3rd Qu.:40.88 3rd Qu.:15.03
## Max. :35.41 Max. :46.04 Max. :28.90
## Women High school Share Women Some college Share Women Bachelor's degree Share
## Min. :21.80 Min. :16.60 Min. :10.10
## 1st Qu.:26.45 1st Qu.:25.43 1st Qu.:14.25
## Median :32.25 Median :30.10 Median :18.00
## Mean :32.56 Mean :27.99 Mean :18.18
## 3rd Qu.:39.88 3rd Qu.:31.40 3rd Qu.:22.43
## Max. :41.70 Max. :32.30 Max. :27.10
## Women Advanced degree Share
## Min. : 2.700
## 1st Qu.: 5.425
## Median : 7.600
## Mean : 8.520
## 3rd Qu.:11.300
## Max. :16.800
# Renaming Columns
colnames(wages) <- str_replace_all(colnames(wages), " ", "_")
# Data Preview
head(wages)## # A tibble: 6 × 31
## Date Less_than_HS High_school Some_college `Bachelor's_degree`
## <date> <dbl> <dbl> <dbl> <dbl>
## 1 2022-12-06 16.5 21.9 24.8 41.6
## 2 2021-12-06 16.7 22.3 24.9 41.3
## 3 2020-12-06 17.0 22.7 25.4 41.6
## 4 2019-12-06 16.1 21.6 24 39.6
## 5 2018-12-06 15.9 21.5 23.7 38.9
## 6 2017-12-06 15.9 21.3 23.3 38.6
## # ℹ 26 more variables: Advanced_degree <dbl>, Less_than_HS_Share <dbl>,
## # High_school_Share <dbl>, Some_college_Share <dbl>,
## # `Bachelor's_degree_Share` <dbl>, Advanced_degree_Share <dbl>,
## # Men_Less_than_HS <dbl>, Men_High_school <dbl>, Men_Some_college <dbl>,
## # `Men_Bachelor's_degree` <dbl>, Men_Advanced_degree <dbl>,
## # Men_Less_than_HS_Share <dbl>, Men_High_school_Share <dbl>,
## # Men_Some_college_Share <dbl>, `Men_Bachelor's_degree_Share` <dbl>, …
# Wage Analysis: Grouping and summarizing data by date
wage_analysis <- wages %>%
group_by(Date) %>%
summarize(
Mean_Less_than_HS = mean(`Less_than_HS`, na.rm = TRUE), # Calculate mean wage for less than high school
Mean_High_School = mean(`High_school`, na.rm = TRUE), # Calculate mean wage for high school
Mean_Some_College = mean(`Some_college`, na.rm = TRUE), # Calculate mean wage for some college
Mean_Bachelors_Degree = mean(`Bachelor's_degree`, na.rm = TRUE), # Calculate mean wage for bachelor's degree
Mean_Advanced_Degree = mean(`Advanced_degree`, na.rm = TRUE) # Calculate mean wage for advanced degree
)
# Plotting the data: Creating a line plot for each education level. Applying minimal theme for a cleaner look
ggplot(wage_analysis, aes(x = Date)) +
geom_line(aes(y = Mean_Less_than_HS, color = "Less than HS")) + # Line plot for 'Less than HS'
geom_line(aes(y = Mean_High_School, color = "High School")) + # Line plot for 'High School'
geom_line(aes(y = Mean_Some_College, color = "Some College")) + # Line plot for 'Some College'
geom_line(aes(y = Mean_Bachelors_Degree, color = "Bachelor's Degree")) + # Line plot for 'Bachelor's Degree'
geom_line(aes(y = Mean_Advanced_Degree, color = "Advanced Degree")) + # Line plot for 'Advanced Degree'
labs(title = "Average Hourly Wage Over Time by Education Level", # Adding plot title and axis labels
x = "Year",
y = "Average Hourly Wage (USD)",
color = "Education Level") +
theme_minimal() #Conclusion
#The analysis focused on the trends of average hourly wages across five educational levels from 1973 to 2022. The results indicated that individuals with higher education levels generally earn more, and this wage disparity has been consistent over time. The most significant wage growth was observed in those with advanced degrees, whereas individuals with less than a high school education experienced the least wage growth.# Wage Gender Analysis: Grouping and summarizing data by date
wage_gender_analysis <- wages %>%
group_by(Date) %>%
summarize(
Mean_Men = mean(c(`Men_Less_than_HS`, `Men_High_school`, `Men_Some_college`, `Men_Bachelor's_degree`, `Men_Advanced_degree`), na.rm = TRUE), # Calculate average wage for men across all education levels
Mean_Women = mean(c(`Women_Less_than_HS`, `Women_High_school`, `Women_Some_college`, `Women_Bachelor's_degree`, `Women_Advanced_degree`), na.rm = TRUE) # Calculate average wage for women across all education levels
)
# Plotting the Data: Creating a line plot for gender-based wage comparison
ggplot(wage_gender_analysis, aes(x = Date)) +
geom_line(aes(y = Mean_Men, color = "Men")) + # Line plot for men's average wages
geom_line(aes(y = Mean_Women, color = "Women")) + # Line plot for women's average wages
labs(title = "Average Hourly Wage Over Time by Gender", # Adding plot title and axis labels
x = "Year",
y = "Average Hourly Wage (USD)",
color = "Gender") +
theme_minimal() + # Applying minimal theme for a cleaner look
theme(legend.position = "bottom") # Adjusting legend position#Conclusion
#The study also investigated the average hourly wages for men and women across all education levels from the 1980s to the early 2020s. The data revealed a persistent gender wage gap, with men's wages consistently higher than women's. Despite overall wage growth for both genders, men's wages increased at a more pronounced rate, particularly in recent years.# Reshaping Data: Converting wide format to long format for degree shares
wages_long <- wages %>%
pivot_longer(
cols = c(`Men_Bachelor's_degree_Share`, `Women_Bachelor's_degree_Share`,
`Men_Advanced_degree_Share`, `Women_Advanced_degree_Share`), # Columns to pivot
names_to = "Degree", # New column for degree names
values_to = "Share" # New column for share values
)
# Creating Combined Category for Degree and Gender
wages_long <- wages_long %>%
mutate(Gender_Degree = ifelse(
grepl("Men", Degree),
paste("Men's", sub("_Share", "", sub("Men_", "", Degree))), # Create label for men's degrees
paste("Women's", sub("_Share", "", sub("Women_", "", Degree))) # Create label for women's degrees
))
# Plotting the Data: Creating a scatter plot with lines
ggplot(wages_long, aes(x = Date, y = Share, color = Gender_Degree, group = Gender_Degree)) +
geom_line() + # Adding line plot
geom_point(size = 2, aes(size = Share)) + # Adding points to the plot with size based on share
scale_size(range = c(1, 5)) + # Adjusting the scale of point sizes
scale_color_brewer(palette = "Set3") + # Using a color palette for differentiation
labs(
title = "Comparison of Degree Shares by Gender Over Time", # Adding title and labels
x = "Year",
y = "Share",
color = "Gender&Degree"
) +
theme_minimal() + # Applying a minimal theme for aesthetics
theme(
legend.position = "bottom", # Adjusting legend position
plot.title = element_text(size = 14, face = "bold"), # Styling the plot title
axis.text.x = element_text(angle = 45, hjust = 1), # Styling the x-axis text
axis.title = element_text(size = 12) # Styling the axis titles
)#Conclusion
#The final analysis examined the share of bachelor's and advanced degrees held by men and women from 1980 to 2020. The data showed that women's share in both degree types has increased more rapidly than men's. By the mid-1990s, women began surpassing men in bachelor's degrees, a trend that continued into advanced degrees, nearing parity by 2020.The analyses conducted reveal a multifaceted picture of educational and economic trends over the past few decades. Key findings include:
Education Advancement: Significant strides have been made by women in higher education, surpassing men in bachelor’s degrees by the mid-1990s and closing the gap in advanced degrees. Persistent Gender Wage Gap: Despite educational gains, the gender wage gap remains a consistent issue. Economic Benefits of Education: Higher education levels correlate with increased wage growth, underscoring the value of further education. Wage Growth Trends: While wages for both genders have increased, the growth rate for men’s wages has been more pronounced. These findings highlight the need for ongoing efforts to address the disparities in wage and education, ensuring equitable benefits from economic and educational advancements.