library(tidyverse)
library(epiextractr)Wage analysis
Note: Users will need to install epiextractr for this example. Refer to EPI packages for R for installation instructions.
Defining the universe for wage analysis
For standard definition (i.e., no special exclusions or inclusions), filter to age >= 16, emp == 1, and cow1 <= 5. This is non-self-employed, non-self-incorporated, employed workers at or over 16 years old.
Note: self-employed and self-incorporated workers do not have wages in the CPS ORG, so this filter is somewhat duplicative when analyzing wage data. It’s necessary for Basic data.
Note: this is not, of course, always the target universe (e.g., EPOPs). Use discretion when defining the sample.
cps_org <- load_org(2020:2024, "year", "age", "statefips", "wage", "emp", "union", "orgwgt", "cow1") |>
filter(age >= 16, emp == 1, cow1 <= 5) Inflation adjusting
Use chained CPI c_cpi_u for analysis; and chained extended c_cpi_u_extended for analysis pre-2000 (package: realtalk).
Median wages
Use averaged_median in the epidatatools package, rather than binipolate. Note, quantiles_n and quantiles_w default to the following so are not strictly necessary to include in the code (although may help others understand the process).
wages_gender <- cps_org |>
summarise(
wage_median = averaged_median(
x = realwage,
w = orgwgt/12,
quantiles_n = 9L,
quantiles_w = c(1:4, 5, 4:1)),
n=n(),
.by=c(female, year)
) Imputed wage filtering
There may be instances where you want to remove imputed wages allocated by the BLS. This is especially common when dealing with union vs non-union wage comparisons, as the BLS does not account for union status when calculating imputed wages. Because of 1) the way that the a_earnhour and a_weeklypay variables are coded and 2) that filter() default drops N/A values, simply coding for filter(a_earnhour != 1) (i.e., dropping imputed wages) will also remove all non-hourly workers. You do not want this. Use this code to preserve salaried workers with self-reported wages:
If you want to keep imputed wages in the sample for analysis:
mutate(
wage_imputed = case_when(
paidhre == 1 & a_earnhour == 1 ~ 1,
paidhre == 0 & a_weekpay == 1 ~ 1,
.default = 0
)
) You can always filter to wage_imputed = 0 if you want to remove the imputed wages.
If you want to filter out imputed wages from the start:
filter_out(a_earnhour == 1 & paidhre == 1 | a_weekpay == 1 & paidhre == 0) These should result in the same samples for non-imputed wages. You can check this by running crosstab(data, paidhre, wage_imputed) and crosstab(data, paidhre, a_earnhour).