Compiles education from participant, mother or father depending on source availability. Made for ease of testing and reporting education SES of family

edu_compile(data, participant, mother, father)

Arguments

data

MOAS-like data.frame

participant

unquoted column of 4 category education for participant

mother

unquoted column of 4 category education for participant's mother

father

unquoted column of 4 category education for participant's father

Value

dataframe with three new columns

See also

Examples


edu <- data.frame(
    edu4 = c("3", "High school", 1, NA,
         "University/University college (> 4 years)", NA, 
          "University/University college (< 4 years)"),
    edu9 = c(7,7,8,NA,"Primary school (6 years)",5, 9),
    edu_years = c(NA, 12, 9, NA, 19, 19, NA),
    mother = c("3", "High school", 1, NA,
               "University/University college (> 4 years)",
               "University/University college (> 4 years)", 
               "University/University college (< 4 years)"),
    father = c(7,7,8,4,"Primary school (6 years)",5, 10),
    stringsAsFactors = FALSE
    )
 
 library(dplyr)
 edu %>% 
     mutate(
        mother = ifelse(mother == "3", NA, mother),
        mother = edu4_factorise(mother),
        father = edu9_reduce(edu9_factorise(father))
     ) %>% 
     edu_compile(
        participant = edu4,
        mother = mother,
        father = father
        )
#>                                        edu4                     edu9 edu_years
#> 1                                         3                        7        NA
#> 2                               High school                        7        12
#> 3                                         1                        8         9
#> 4                                      <NA>                     <NA>        NA
#> 5 University/University college (> 4 years) Primary school (6 years)        19
#> 6                                      <NA>                        5        19
#> 7 University/University college (< 4 years)                        9        NA
#>                                      mother
#> 1                                      <NA>
#> 2                               High school
#> 3                  Primary school (9 years)
#> 4                                      <NA>
#> 5 University/University college (> 4 years)
#> 6 University/University college (> 4 years)
#> 7 University/University college (< 4 years)
#>                                      father
#> 1 University/University college (< 4 years)
#> 2 University/University college (< 4 years)
#> 3 University/University college (> 4 years)
#> 4                               High school
#> 5                                      <NA>
#> 6                               High school
#> 7                                      <NA>
#>                          edu_compiled_code4 edu_compiled_years
#> 1 University/University college (< 4 years)                 16
#> 2                               High school                 12
#> 3                  Primary school (9 years)                  9
#> 4                               High school                 12
#> 5 University/University college (> 4 years)                 19
#> 6 University/University college (> 4 years)                 19
#> 7 University/University college (< 4 years)                 16
#>   edu_compiled_source
#> 1         Participant
#> 2         Participant
#> 3         Participant
#> 4              Father
#> 5         Participant
#> 6              Mother
#> 7         Participant