R/aps_clean_education.R

Defines functions aps_clean_education

Documented in aps_clean_education

#' Clean education data
#'
#' Construct highest qualification variable and a binary variable for whether or not the
#' individual is degree-level educated.
#'
#' @return Returns a new set of variables
#' @export
aps_clean_education <- function(
  data
) {

  if("hiqual" %in% colnames(data)) {

  ### 2015-2018 based on hiqul15d
  data[year %in% 2015:2019 & hiqual == 1, highest_qual := "Degree"]
  data[year %in% 2015:2019 & hiqual == 2, highest_qual := "Level 4+ Vocational"]
  data[year %in% 2015:2019 & hiqual == 3, highest_qual := "Level 3"]
  data[year %in% 2015:2019 & hiqual == 4, highest_qual := "Level 2"]
  data[year %in% 2015:2019 & hiqual == 5, highest_qual := "Below Level 2/Other"]
  data[year %in% 2015:2019 & hiqual == 6, highest_qual := "No qualifications"]
  ### 2013-2014 based on hiqul11d

  data[year %in% 2013:2014 & hiqual == 1, highest_qual := "Degree"]
  data[year %in% 2013:2014 & hiqual == 2, highest_qual := "Level 4+ Vocational"]
  data[year %in% 2013:2014 & hiqual == 3, highest_qual := "Level 3"]
  data[year %in% 2013:2014 & hiqual == 4, highest_qual := "Level 2"]
  data[year %in% 2013:2014 & hiqual == 5, highest_qual := "Below Level 2/Other"]
  data[year %in% 2013:2014 & hiqual == 6, highest_qual := "No qualifications"]
  ### 2011-2012 based on 31 "qual" vars

  # create a binary degree variable

  data[year %in% 2011:2019 & highest_qual %in% c("Degree","Level 4+ Vocational"), degree := "degree"]
  data[year %in% 2011:2019 & highest_qual %in% c("Level 3","Level 2","Below Level 2/Other","No qualifications"), degree := "no_degree"]

  # drop surplus variables
  data <- subset(data,select = -c(hiqual))

} else {
  data[year %in% 2004:2010, highest_qual := as.character(NA)]
  data[year %in% 2004:2010, degree := as.character(NA)]
}



  return(data)

}
djmorris1989/apsclean documentation built on June 17, 2020, 9:02 p.m.