-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunion_density.qmd
64 lines (46 loc) · 1.85 KB
/
union_density.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
title: "Historical state union density"
author: 'Daniel Perez, EARN/EPI'
---
Contact: [dperez\@epi.org](mailto:%[email protected])
### This script uses Current Population Survey (CPS) microdata extracts from <https://microdata.epi.org/> to calculate union density from 1983-Present.
```{r Libraries, message=FALSE}
library(tidyverse)
library(here)
library(epiextractr)
```
Load CPS data using [epiextractr](epi_microdata.qmd)
```{r Load CPS Basic}
basic <- load_basic(1983:2022, year, month, statefips, basicwgt, union, unmem, age, emp, selfemp, selfinc) %>%
filter(age>=16, emp==1) %>%
#remove self-employed and self-incorporated workers from sample
mutate(selfemp0 = ifelse(selfemp==1 & !is.na(selfemp), yes=1, no=0),
selfinc0 = ifelse(selfinc==1 & !is.na(selfinc), yes=1, no=0)) %>%
filter(selfemp0==0, selfinc0==0)
```
Calculate US union density 1983--2022
```{r National}
#US union members and union represented by year, 1983-2022
density_us <- basic %>%
group_by(year) %>%
summarise(represented_share = weighted.mean(union, w=basicwgt/12, na.rm=TRUE),
rep_n = sum(union, na.rm=TRUE),
member_share = weighted.mean(unmem, w=basicwgt/12, na.rm=TRUE),
memb_n = sum(unmem, na.rm=TRUE),
wgt_memb = sum(unmem * basicwgt/12, na.rm=TRUE))
density_us
```
Calculate state level union representation, 1983--2022
```{r Year and state}
#Union representation by year and state, 1983–Present
density_state <- basic %>%
summarise(represented_share = weighted.mean(union, w=basicwgt/12, na.rm=TRUE),
.by = c(year, statefips)) %>%
#Turn statefips labels into strings
mutate(statefips = haven::as_factor(statefips)) %>%
#sort by year and state
arrange(year, statefips) %>%
#reshape data
pivot_wider(id_cols = year, names_from = statefips, values_from = represented_share)
density_state
```