Skip to content

Instantly share code, notes, and snippets.

@naomispence
Last active September 23, 2025 21:05
Show Gist options
  • Select an option

  • Save naomispence/2160a8a5a0cf96505542d57aad8b47ae to your computer and use it in GitHub Desktop.

Select an option

Save naomispence/2160a8a5a0cf96505542d57aad8b47ae to your computer and use it in GitHub Desktop.
#if you need to recode any of your variable values, you should do it before you label your dummy codes
wave5addhealth$H5HR2[wave5addhealth$H5HR2 == 6] <- 5
#the line right above this note changes the old dummy code 6 to a dummy code of 5, which combines the two groups.
#if you need to code out missing data (R calls it NA), you would use the example shown in the line below.
wave5addhealth$VARNAME[wave5addhealth$VARNAME == 97] <- NA
#in the line above, the number inside the ] needs to be the dummy code for missing data on your variable.
# the two lines below tell R to treat your categorical variable as a categorical variable (factor) and label the dummy codes
wave5addhealth$H5HR2 <- factor(wave5addhealth$H5HR2)
levels(wave5addhealth$H5HR2) <- c("own home", "parent's home", "another's home", "homeless", "other")
#on the line above this note, your labels are in quotes and they must go in the order of the dummy codes.
#the line below will label your variable (like making a title)
label(wave5addhealth$H5HR2) <- "Living Arrangements"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment