It is impossible to know what truly would have happened in California schools if the law had never happened. However, we can look for another state whose average student wages that follow a similar pattern over time — but did not receive the same treatment. We can use the other state’s data to approximate the counterfactual. With DID, we use the trend of a control group to estimate the counterfactual trend for the treated. In other words, we use DID to estimate the average treatment effect on the treated (ATT).

In this example, a control trend might be the average student wage of universities in Washington, given that Washington did not implement a new minimum wage law. We can view these two groups in a single plot using the following code:

# import library library(ggplot2) # plot wages versus years by state ggplot(data = wages, aes(x = year, y = avg_wage, color = state, linetype = state)) + geom_line() + #vertical line at 2016 geom_vline(xintercept = 2016, linetype = "dashed") + #x-axis scale 2007 to 2017 scale_x_continuous(breaks = c(2007:2017))

plot of Average Student Wages vs. Year with two states

We can see that in the years leading up to 2016, the average minimum wage at Washington colleges followed a very similar pattern to the California colleges, only shifted lower. We hope that these similar patterns account for other important variables, such as the impact on wages of living costs and necessary student expenses.



The tickets dataset also contains data on average ticket sales in Toronto. Create a line plot that shows the ticket sales for both Toronto and Sydney over the same years. Be sure to change the color and type of line by city. Does Toronto have a similar trend in ticket sales from 2012 to 2018?

Note: you can optionally add a dashed vertical line at 2018 and set the x-axis scale using the functions in the last two lines of code shown in the narrative.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?