# Create the dummy variable as defined above CASchools$D <- CASchools$STR < 20 # Plot the data plot(CASchools$D, CASchools$score, # provide the data to be plotted pch = 20, # use filled circles as plot symbols cex = 0.5, # set size of plot symbols to 0.5 col = "Steelblue", # set the symbols' color to "Steelblue" xlab = expression(D[i]), # Set title and axis names ylab = "Test Score", main = "Dummy Regression")
If you want to reproduce the exact plot you need to run the following code:
CASchools$D <- CASchools$STR < 20 # Create the dummy variable as defined above
mean.score.for.D.1 <- mean( CASchools$score[ CASchools$D == TRUE ] ) # Compute the average score when D=1 (low STR)
mean.score.for.D.0 <- mean( CASchools$score[ CASchools$D == FALSE ] ) # Compute the average score when D=0 (high STR)
plot( CASchools$score ~ CASchools$D, # Plot the data
pch = 19,
cex = 0.5,
col = "Steelblue",
xlab = expression(D[i]),
ylab = "Test Score",
main = "Dummy Regression")
points( y = mean.score.for.D.0, x = 0, col="red", pch = 19) # Add the average for each group
points( y = mean.score.for.D.1, x = 1, col="red", pch = 19)