Gender Pay Gap: An Analysis

Sidney Coates

2024-04-16

Data Source

https://github.com/rfordatascience/tidytuesday/tree/master/data/2019

Questions

  1. In 2015, for occupations where men made more than women, what were the top ten occupations with the highest pay gap between men and women?

  2. In 2015, for occupations where men made more than women, what were the top ten occupations with the smallest pay gap between men and women?

  3. In 2015, what were the top ten occupations where women made more than men?

  4. In 2015, what was the average pay gap for occupations where men made more than women and the proportion of female workers was 50% or more?

  5. In 2015, what was the average pay gap for occupations where men made more than women and the proportion of female workers was less than 50%?

Setup

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidymodels)
## ── Attaching packages ────────────────────────────────────── tidymodels 1.2.0 ──
## ✔ broom        1.0.5      ✔ rsample      1.2.1 
## ✔ dials        1.2.1      ✔ tune         1.2.0 
## ✔ infer        1.0.7      ✔ workflows    1.1.4 
## ✔ modeldata    1.3.0      ✔ workflowsets 1.1.0 
## ✔ parsnip      1.2.1      ✔ yardstick    1.3.1 
## ✔ recipes      1.0.10     
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## ✖ scales::discard() masks purrr::discard()
## ✖ dplyr::filter()   masks stats::filter()
## ✖ recipes::fixed()  masks stringr::fixed()
## ✖ dplyr::lag()      masks stats::lag()
## ✖ yardstick::spec() masks readr::spec()
## ✖ recipes::step()   masks stats::step()
## • Use suppressPackageStartupMessages() to eliminate package startup messages
jobs_gender <- read.csv("C:\\Users\\coate\\Downloads\\jobs_gender.csv")
save(jobs_gender, file = "jobs_gender.RData")
load("~/jobs_gender.RData")

Description of the Data

str(jobs_gender)
## 'data.frame':    2088 obs. of  12 variables:
##  $ year                 : int  2013 2013 2013 2013 2013 2013 2013 2013 2013 2013 ...
##  $ occupation           : chr  "Chief executives" "General and operations managers" "Legislators" "Advertising and promotions managers" ...
##  $ major_category       : chr  "Management, Business, and Financial" "Management, Business, and Financial" "Management, Business, and Financial" "Management, Business, and Financial" ...
##  $ minor_category       : chr  "Management" "Management" "Management" "Management" ...
##  $ total_workers        : int  1024259 977284 14815 43015 754514 44198 109703 489048 990611 14656 ...
##  $ workers_male         : int  782400 681627 8375 17775 440078 16141 72873 354369 460842 3387 ...
##  $ workers_female       : int  241859 295657 6440 25240 314436 28057 36830 134679 529769 11269 ...
##  $ percent_female       : num  23.6 30.3 43.5 58.7 41.7 63.5 33.6 27.5 53.5 76.9 ...
##  $ total_earnings       : int  120254 73557 67155 61371 78455 74114 62187 99167 70456 71927 ...
##  $ total_earnings_male  : int  126142 81041 71530 75190 91998 90071 66579 101318 90278 97552 ...
##  $ total_earnings_female: int  95921 60759 65325 55860 65040 66052 55079 90940 57406 68207 ...
##  $ wage_percent_of_male : num  76 75 91.3 74.3 70.7 ...
summary(jobs_gender)
##       year       occupation        major_category     minor_category    
##  Min.   :2013   Length:2088        Length:2088        Length:2088       
##  1st Qu.:2014   Class :character   Class :character   Class :character  
##  Median :2014   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :2014                                                           
##  3rd Qu.:2015                                                           
##  Max.   :2016                                                           
##                                                                         
##  total_workers      workers_male     workers_female    percent_female  
##  Min.   :    658   Min.   :      0   Min.   :      0   Min.   :  0.00  
##  1st Qu.:  18687   1st Qu.:  10765   1st Qu.:   2364   1st Qu.: 10.73  
##  Median :  58997   Median :  32302   Median :  15238   Median : 32.40  
##  Mean   : 196055   Mean   : 111515   Mean   :  84540   Mean   : 36.00  
##  3rd Qu.: 187415   3rd Qu.: 102644   3rd Qu.:  63327   3rd Qu.: 57.31  
##  Max.   :3758629   Max.   :2570385   Max.   :2290818   Max.   :100.00  
##                                                                        
##  total_earnings   total_earnings_male total_earnings_female
##  Min.   : 17266   Min.   : 12147      Min.   :  7447       
##  1st Qu.: 32410   1st Qu.: 35702      1st Qu.: 28872       
##  Median : 44437   Median : 46825      Median : 40191       
##  Mean   : 49762   Mean   : 53138      Mean   : 44681       
##  3rd Qu.: 61012   3rd Qu.: 65015      3rd Qu.: 54813       
##  Max.   :201542   Max.   :231420      Max.   :166388       
##                   NA's   :4           NA's   :65           
##  wage_percent_of_male
##  Min.   : 50.88      
##  1st Qu.: 77.56      
##  Median : 85.16      
##  Mean   : 84.03      
##  3rd Qu.: 90.62      
##  Max.   :117.40      
##  NA's   :846

Cleaning and Preparation

jobs_gender_2015 <- subset(jobs_gender, year == 2015)

Question 1

In 2015, for occupations where men made more than women, what were the top ten occupations with the highest pay gap between men and women?

Solution 1

jobs_gender_2015$pay_gap <- jobs_gender_2015$total_earnings_male - jobs_gender_2015$total_earnings_female
desc_pay_gap <- jobs_gender_2015[order(-jobs_gender_2015$pay_gap), ] 
top10_high_pay_gap <- desc_pay_gap %>% select("occupation", "pay_gap") %>% head(10)
top10_high_pay_gap
##                                                        occupation pay_gap
## 1209                                      Physicians and surgeons   70553
## 1172              Judges, magistrates, and other judicial workers   49731
## 1312 Securities, commodities, and financial services sales agents   43060
## 1426 Electrical and electronics repairers, industrial and utility   41974
## 1102                             Financial specialists, all other   41915
## 1547                         Ship and boat captains and operators   39744
## 1115                                               Mathematicians   38571
## 1045                                             Chief executives   38561
## 1096                                  Personal financial advisors   38346
## 1054                           Compensation and benefits managers   36341

Graph 1

ggplot(top10_high_pay_gap, aes(x = reorder(occupation, -pay_gap), y = pay_gap)) +
  geom_bar(stat = "identity", fill = "red", color = "black") +
  labs(title = "Top Ten Occupations With Highest Pay Gap Between Men and Women",
       x = "Occupation",
       y = "Pay Gap (USD)") +
  theme_minimal() +
  coord_flip() +
  scale_y_continuous(breaks = seq(0, max(top10_high_pay_gap$pay_gap), by = 10000)) +
  theme(axis.text.x = element_text(size = 10, angle = 45, hjust = 1),
        axis.text.y = element_text(size = 10),
        axis.title = element_text(size = 12),
        plot.title = element_text(size = 14, hjust = 1))

Question 2

In 2015, for occupations where men made more than women, what were the top ten occupations with the smallest pay gap between men and women?

Solution 2

asc_pay_gap <- jobs_gender_2015[order(jobs_gender_2015$pay_gap), ] 
top10_low_pay_gap <- asc_pay_gap %>% filter(pay_gap >= 0) %>% select("occupation", "pay_gap") %>% head(10)
top10_low_pay_gap
##                                                                        occupation
## 1  Milling and planing machine setters, operators, and tenders, metal and plastic
## 2                                       Baggage porters, bellhops, and concierges
## 3                                                                          Actors
## 4                      Miscellaneous therapists, including exercise physiologists
## 5                                                        Cargo and freight agents
## 6                                       Miscellaneous personal appearance workers
## 7                         Food preparation and serving related workers, all other
## 8                         Drywall installers, ceiling tile installers, and tapers
## 9                                            Hotel, motel, and resort desk clerks
## 10                                   Automotive and watercraft service attendants
##    pay_gap
## 1       78
## 2      132
## 3      169
## 4      170
## 5      206
## 6      238
## 7      414
## 8      460
## 9      575
## 10     646

Graph 2

ggplot(top10_low_pay_gap, aes(x = reorder(occupation, -pay_gap), y = pay_gap)) +
  geom_bar(stat = "identity", fill = "blue", color = "black") +
  labs(title = "Top Ten Occupations With Smallest Pay Gap Between Men and Women",
       x = "Occupation",
       y = "Pay Gap (USD)") +
  coord_flip() +
  scale_y_continuous(breaks = seq(0, max(top10_high_pay_gap$pay_gap), by = 100)) +
  theme_minimal() +
  theme(axis.text.x = element_text(size = 10, angle = 45, hjust = 1),
        axis.text.y = element_text(size = 10),
        axis.title = element_text(size = 12),
        plot.title = element_text(size = 14, hjust = 1))

Question 3

In 2015, what were the top 10 occupations where women made more than men?

Solution 3

pay_gap_favors_women <- jobs_gender_2015[order(jobs_gender_2015$pay_gap), ]
top10_pay_gap_favors_women <- pay_gap_favors_women %>% select("occupation", "pay_gap") %>% head(10)
top10_pay_gap_favors_women 
##                                                                   occupation
## 1501                                        Fabric and apparel patternmakers
## 1527                    Cooling and freezing equipment operators and tenders
## 1412 Derrick, rotary drill, and service unit operators, oil, gas, and mining
## 1436                                                  Small engine mechanics
## 1454                  Helpers--installation, maintenance, and repair workers
## 1133      Mining and geological engineers, including mining safety engineers
## 1255                                                   Fish and game wardens
## 1130                                   Marine engineers and naval architects
## 1376                                                         Animal breeders
## 1387                 Cement masons, concrete finishers, and terrazzo workers
##      pay_gap
## 1501  -38337
## 1527  -37427
## 1412  -32229
## 1436  -23008
## 1454  -15921
## 1133  -13961
## 1255  -12118
## 1130  -10309
## 1376   -9934
## 1387   -8498

Graph 3

ggplot(top10_pay_gap_favors_women, aes(x = reorder(occupation, -pay_gap), y = pay_gap)) +
  geom_bar(stat = "identity", fill = "green", color = "black") +
  labs(title = "Top Ten Occupations Where Women Made More Than Men",
       x = "Occupation",
       y = "Pay Gap (USD)") +
  coord_flip() +
  theme_minimal() +
  theme(axis.text.x = element_text(size = 10, angle = 45, hjust = 1),
        axis.text.y = element_text(size = 10),
        axis.title = element_text(size = 12),
        plot.title = element_text(size = 14, hjust = 1)) 

Question 4

In 2015, what was the average pay gap for occupations where men made more than women and the proportion of female workers was 50% or more?

Solution 4

over_half_women <- jobs_gender_2015 %>% filter(percent_female >= 50.0, pay_gap > 0)
pg_more_women <- over_half_women$pay_gap
avg_pg_more_women <- mean(pg_more_women)
avg_pg_more_women
## [1] 8486.482

Graph 4

ggplot(over_half_women, aes(x = percent_female, y = pay_gap)) +
  geom_point() +
  labs(title = "Proportion of Women (>= 50%) vs Pay Gap",
       x = "Proportion of Women (%)",
       y = "Pay Gap (USD)") +
  theme_minimal() +
  theme(axis.text.x = element_text(size = 10, hjust = 1),
        axis.text.y = element_text(size = 10),
        axis.title = element_text(size = 12),
        plot.title = element_text(size = 14, hjust = .5)) 

Question 5

In 2015, what was the average pay gap for occupations where men made more than women and the proportion of female workers was less than 50%?

Solution 5

under_half_women <- jobs_gender_2015 %>% filter(percent_female < 50.0, pay_gap > 0)
pg_less_women <- under_half_women$pay_gap
avg_pg_less_women <- mean(pg_less_women)
avg_pg_less_women
## [1] 11055.19

Graph 5

ggplot(under_half_women, aes(x = percent_female, y = pay_gap)) +
  geom_point() +
  labs(title = "Proportion of Women (< 50%) vs Pay Gap",
       x = "Proportion of Women (%)",
       y = "Pay Gap (USD)") +
  theme_minimal() +
  theme(axis.text.x = element_text(size = 10, hjust = 1),
        axis.text.y = element_text(size = 10),
        axis.title = element_text(size = 12),
        plot.title = element_text(size = 14, hjust = .5))