R/aps_clean_hours_earn.R

Defines functions aps_clean_hours_earn

Documented in aps_clean_hours_earn

#' 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)
}
djmorris1989/apsclean documentation built on June 17, 2020, 9:02 p.m.