R/HISEI.R

Defines functions get_HISEI

Documented in get_HISEI

#' @title get_HISEI
#' @description Función que calcula el indice HISEI
#' @details bkla
#' @examples
#' dataproc<-get_HISEI()
#' @export
get_HISEI <-
  function(){
    #Load ISCO-08 to ISEI-08
    conversion_isco_to_isei<-readr::read_csv("data/isco08toisei08.csv")
    #Load open questions coded

    # questionaire<- read_xlsx("data/PISAQclean.xlsx")%>%
    #   select(c('idUser_int','15-ST014','15-ST015'))
    # questionaire_isco <-
    #   questionaire %>%
    #   rename(`BMMJ1` = `15-ST014`,
    #          `BFMJ1` = `15-ST015`) %>%
    #   distinct()
    questionaire_isco <- readr::read_csv("data/input_pfs_context_mex_2018.csv")%>%select(stidstd,BMMJ1,BFMJ1)
    #After getting BMMJ1 (Mother's data)& BFMJ1 (Father's data), ISCO are converted to ISEI codes
    ISEI <- questionaire_isco %>%
      #select(idUser_int, `BMMJ1`, `BFMJ1`) %>%
      select(stidstd, `BMMJ1`, `BFMJ1`) %>%
      left_join(conversion_isco_to_isei, by = c("BMMJ1" = "ISCO08")) %>% rename(ISEIm = ISEI08) %>%
      left_join(conversion_isco_to_isei, by = c("BFMJ1" = "ISCO08")) %>% rename(ISEIf = ISEI08)
    #Computing HISEI, highest ISEI from parental occupation
    HISEI <- ISEI %>%
      rowwise() %>%
      mutate(HISEI = max(c(ISEIf, ISEIm), na.rm = TRUE))%>%
      rename(`stidstd` = `stidstd`)%>%
      distinct()

    # Removing infinites introduced when getting max values of
    # all-NA cases of ISEIf & ISEIm; replacing them with NA for simplicity
    is.na(HISEI$HISEI) <-
      do.call(cbind, lapply(HISEI$HISEI, is.infinite))
    #Returning HISEI Values
    #print(conversion_isco_to_isei)
    return(HISEI)
  }

#  data<-read_xlsx(path = "data/output_StdQ_golddataset.xlsx")
#  dataproc<-get_HISEI()
# compar<-inner_join(dataproc %>%
#                      select(stidstd,BMMJ1,BFMJ1,HISEI),
#                    data %>%
#                      select(stidstd,BMMJ1,BFMJ2,HISEI),
#                    by=c("stidstd"="stidstd"))%>%
#    mutate(diff=abs(HISEI.x-HISEI.y))
#  compar<-compar[,order(colnames(compar))]
knotion/PFSkit documentation built on Feb. 12, 2020, 12:16 p.m.