#' Clean earnings and hours of work data
#'
#' Converts weekly earnings into real terms, constructs actual and usual hours worked per week
#' and two hourly wage measures based on these hours variables.
#'
#' @return Returns a new set of variables
#' @export
aps_clean_hours_earn <- function(
data
) {
# merge CPI into the main dataset
data <- merge(data,aps_cpi,by = c("month","year"))
# convert weekly earnings from nominal to real
data[, weekly_earnings := grsswk*(100/cpi_value) ]
data[, weekly_earnings_nom := grsswk ]
# calculate hourly wages for both usual and actual hours worked.
data[, awage := weekly_earnings/ttachr ]
data[, uwage := weekly_earnings/ttushr ]
data[, awage_nom := weekly_earnings_nom/ttachr ]
data[, uwage_nom := weekly_earnings_nom/ttushr ]
data[, ahours := ttachr ]
data[, uhours := ttushr ]
# drop surplus variables
data <- subset(data,select = -c(grsswk,cpi_value,ttachr,ttushr))
return(data)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.