AlisonLanski / IPEDSuploadables

Producing uploadable txt files for IPEDS reporting, one submission at a time
https://alisonlanski.github.io/IPEDSuploadables/
Other
8 stars 5 forks source link

make_ef1_part_D failure #64

Closed jasonpcasey closed 2 years ago

jasonpcasey commented 2 years ago

Describe the bug *make_ef1_part_D() will fail when there are either no non-degree students or no new non-degree students. The following filter is the problem:

           dplyr::filter(.data$ISDEGREECERTSEEKING == 0 & .data$STUDENTLEVEL == "Undergraduate" &
                           (.data$ISFIRSTTIME == 1 | .data$ISTRANSFER == 1)) %>%

If the number of qualifying cases is zero, dplyr::summarize will throw the following error:

nms %in% c('"i", "x", "") are not all TRUE

Additional context Perhaps create a dichotomous variable using the same criterion as the filter and take the sum:

  partD <- df %>%
           dplyr::select(.data$UNITID,
                         .data$ISDEGREECERTSEEKING,
                         .data$STUDENTLEVEL,
                         .data$ISFIRSTTIME,
                         .data$ISTRANSFER) %>%
           dplyr::mutate(FTND = as.integer(.data$ISDEGREECERTSEEKING == 0 & .data$STUDENTLEVEL == "Undergraduate" &
                                            (.data$ISFIRSTTIME == 1 | .data$ISTRANSFER == 1))) %>%
           dplyr::group_by(.data$UNITID) %>%
           dplyr::summarise(COUNT = sum(FTND, na.rm = T) %>%
           dplyr::ungroup() %>%
           #format for upload
           dplyr::transmute(UNITID = paste0("UNITID=", .data$UNITID),
                            SURVSECT = "SURVSECT=EF1",
                            PART = "PART=D",
                            COUNT = paste0("COUNT=", .data$COUNT)
                           )