Practice Problem Set 6: Functions and Iteration
Run the following code to load the data. View the codebook and other information on the on the data here.
Create dummy variables for the race categorical variable. There should be three new variables:
black(1 if the race is black, 0 otherwise),hispanic(1 if race is hispan, 0 otherwise), andwhite(1 if race is white, 0 otherwise).Write code that calculates the proportion of black students in treatment group and the control group. Then take the difference between those two proportions.
Create a function using the code you wrote in Q3 that takes in a vector containing treatment indicator and the vector containing a binary variable. The function then calculates the proportions in the treatment and control group as well as the difference in the proportions.
Write code to run this function for the following variables:
black,hispanic,white,married, andnodegree.Update the function from Q4 so that the output now is a data frame or tibble containing the following: (1) the proportion in treatment, (2) proportion in control and (3) the difference in the proportions.
Loop through the variables in Q5 with the updated function.
Now change the function so it takes in a dataset and unquoted variable names as arguments. Look through this blog to see how this works.
Apply the function to the variables listed in Q5.
Challenge Problem: I have bunch of csv files in this folder. I need to read them all in. Each file has data on a different school. Read all the data in and bind them together in one dataset.