Living Situation Function

Share on:

HUD Data Standards, looking at them too much (blurred)

Thanks to HUD's changes to the reference numbers for each of the different "Living Situation" responses (like "Rental by client, no ongoing subsidy" and such), I recently created a really useful function that takes the reference number and returns the text associated to it.

Of course this particular function is only useful if you are using the HUD CSV Export or some other sort of raw HMIS data where the values are numeric references to the text you see in your HMIS software, but even if you don't need this, it is a good demonstration of how creating functions in R can help you with your data transformations.

Allow me to demonstrate!

Using the dplyr package and base R's capabilities to create your own functions, I wrote the following (which you are free to use and copy into your own work)

 1library(dplyr)
 2
 3# I'm assigning a function to the name "living_situation".
 4# The only argument one can use inside this function is the reference number 
 5# ("ReferenceNo") which just refers to the number assigned to the value in
 6# the HUD Data Standards.
 7
 8living_situation <- function(ReferenceNo) {
 9  case_when(
10    ReferenceNo == 16 ~ "Place not meant for habitation",
11    ReferenceNo == 1 ~ "Emergency shelter/ h/motel paid for by a third party/ Host Home shelter",
12    ReferenceNo == 18 ~ "Safe Haven",
13    ReferenceNo == 15 ~ "Foster care home of foster care group home",
14    ReferenceNo == 6 ~ " Hospital or other residential non-psychiatric medical facility",
15    ReferenceNo == 7 ~ "Jail/ prison/ juvenile detention",
16    ReferenceNo == 25 ~ "Long-term care facility or nursing home",
17    ReferenceNo == 4 ~ "Psychiatric hospital/ other psychiatric facility",
18    ReferenceNo == 5 ~ "Substance abuse treatment facility or detox center",
19    ReferenceNo == 29 ~ "Residential project or halfway house with no homeless criteria",
20    ReferenceNo == 14 ~ "H/Motel paid for by household",
21    ReferenceNo == 2 ~ "Transitional housing",
22    ReferenceNo == 32 ~ "Host Home (non-crisis)",
23    ReferenceNo == 13 ~ "Staying or living with friends, temporary tenure",
24    ReferenceNo == 36 ~ "Staying or living in a friend's room, apartment or house",
25    ReferenceNo == 12 ~ "Staying or living with family, temporary tenure",
26    ReferenceNo == 22 ~ "Staying or living with family, permanent tenure",
27    ReferenceNo == 35 ~ "Staying or living in a family member's room, apartment, or house",
28    ReferenceNo == 23 ~ "Staying or living with friends, permanent tenure",
29    ReferenceNo == 26 ~ "Moved from one HOPWA funded project to HOPWA PH",
30    ReferenceNo == 27 ~ "Moved from HOPWA funded project to HOPWA TH",
31    ReferenceNo == 28 ~ "Rental by client, with GPD TIP housing subsidy",
32    ReferenceNo == 19 ~ "Rental by client, with VASH housing subsidy",
33    ReferenceNo == 3 ~ "Permanent housing (other than RRH) for formerly homeless persons",
34    ReferenceNo == 31 ~ "Rental by client, with RRH or equivalent subsidy",
35    ReferenceNo == 33 ~ "Rental by client, with HCV voucher",
36    ReferenceNo == 34 ~ "Rental by client in a public housing unit",
37    ReferenceNo == 10 ~ "Rental by client, no ongoing housing subsidy",
38    ReferenceNo == 20 ~ "Rental by client, with other ongoing housing subsidy",
39    ReferenceNo == 21 ~ "Owned by client, with ongoing housing subsidy",
40    ReferenceNo == 11 ~ "Owned by client, no ongoing housing subsidy",
41    ReferenceNo == 30 ~ "No exit interview completed",
42    ReferenceNo == 17 ~ "Other",
43    ReferenceNo == 24 ~ "Deceased",
44    ReferenceNo == 37 ~ "Worker unable to determine",
45    ReferenceNo == 8 ~ "Client doesn't know",
46    ReferenceNo == 9 ~ "Client refused",
47    ReferenceNo == 99 ~ "Data not collected"
48  )
49}

If you copy this into an R script and run it, you can then use the function living_situation() to immediately turn the reference number into the text straight from the HUD Data Standards.

Here's how I was able to use the function to help me in my work:

 1# let's quickly test it:
 2> living_situation(10)
 3[1] "Rental by client, no ongoing housing subsidy"
 4
 5# let's make up some sample data so we can see how it looks to use it in a 
 6# data frame
 7
 8> enrollments <- tribble(
 9~PersonalID, ~EnrollmentID, ~LivingSituation, ~ProjectType, ~Destination,
1095740,	     85743,     2,	 ES,       NA,
1163857,	     64839,     16,	 RRH,       NA,
1262548,	     32647,     2,	 SH,       10,
1396764,       93826,     16,	 TH,       99,
1485736,	     64749,     2,	 ES,       NA)
15
16# the problem is if I want to show this dataset in my Shiny app (or anywhere a 
17# human being would see it), those numbers are not meaningful without the 
18# lookup table in the Data Standards

Results when you run enrollments
Notice the LivingSituation and Destination columns are indecipherable without the HUD Data Standards or a good memory

1# below I use mutate() from the dplyr package to overwrite the LivingSituation 
2# and the Destination columns with the new values by using the 
3# living_situation function.
4
5> enrollments_for_humans <- enrollments %>%
6     mutate(LivingSituation = living_situation(LivingSituation),
7            Destination = living_situation(Destination))

Results when you run enrollments_for_humans
Notice the LivingSituation and Destination columns are displaying the text.

Since the reference numbers are the same whether we're talking about the "Current Living Situation", the Residence Prior aka "Living Situation", or the "Destination" column, it does not matter which column you're wanting to translate from the reference number to the text, that function will work for all three columns. YAY!

Of course similar functions could be created for Project Type or any other reason you find yourself constantly referring to the HUD CSV specs.

Happy function-creating!