R/MA_MBAY_W_B18.R

Defines functions MA_MBAY_W_B18

Documented in MA_MBAY_W_B18

##' MA_MBAY_W_B18  Percentage of Young women age 20-24 first married by exact age 18
##' ms_afm_18 in github
##' IR
#' @param Rdata  data.frame from surveyPrev::getDHSdata
#'
#' @return A partially processed data.frame that will be used in surveyPrev::getDHSindicator. The whole function can be used as a parameter in surveyPrev::getDHSindicator
#'
#' @author Miaolei Bao, Yunhan Wu, Qianyu Dong
#' @examples
#' \dontrun{
#' dhsData <- getDHSdata(country = "Zambia", indicator = "MA_MBAY_W_B18", year = 2018)
#' }
#'
#' @export
MA_MBAY_W_B18<- function(Rdata){

  # Create yes and no category labels
  yesno <- c("Yes" = 1, "No" = 0)
  # First marriage by age 18
  IRdata <- Rdata %>%
   filter(v013 %in% c(2) )%>%
    mutate(MA_MBAY_W_B18 = case_when(v511>=0 & v511<18 ~ 1, TRUE ~ 0)) %>%
    set_value_labels(MA_MBAY_W_B18 = yesno) %>%
    set_variable_labels(MA_MBAY_W_B18 = "First marriage by age 18")

  colnames(IRdata)[colnames(IRdata) == 'MA_MBAY_W_B18'] <- 'value'

  return(IRdata)
}

Try the surveyPrev package in your browser

Any scripts or data that you put into this service are public.

surveyPrev documentation built on June 19, 2026, 5:06 p.m.