Put it into Practice

Now it’s time to try things out for yourself. Complete each of the following steps, based on what we learned in this chapter.

Unless your instructor tells you otherwise, use an R script to execute all code needed to accomplish the following:

  1. This exercise build directly on the one from Part 4. Once again, load in the Vulnerable Neighborhoods Survey dataset (vns.dta).1 You can download it here and save it on your computer. Or you can load the file directly into R through the Internet with the following URL: https://learndata.net/vns.dta
  1. Create a binary variable indicating perceived discrimination. “Yes” should be coded as 1, “No” should be coded as 0, and “Don’t know” should be coded as missing. Create a two-way frequency table that shows how this new variable maps to the original variable, including missing values.

  2. Run a regression with the binary discrimination measure (created in step 2) as the dependent variable and gender and immstatus as independent variables. Make sure both independent variables are treated as factor (qualitative) variables.

After completing all of this, you should save your R script in a folder that is convenient to access. If you are submitting work to an instructor, they will likely want you to send them both your R script and a Word doc containing your results.


  1. This is a modified version of data obtained from Sønderskov and colleagues: https://doi.org/10.17605/OSF.IO/62BV5 (CC-BY 4.0)↩︎