Skip to content

Instantly share code, notes, and snippets.

@airalcorn2
Created July 3, 2018 16:36
Show Gist options
  • Save airalcorn2/67241015f781c872305c4b9ee8bf0a00 to your computer and use it in GitHub Desktop.
Save airalcorn2/67241015f781c872305c4b9ee8bf0a00 to your computer and use it in GitHub Desktop.
Plotting fatality rates for states that had a change in right-to-work laws from this paper --> https://oem.bmj.com/content/early/2018/06/13/oemed-2017-104747.
# Michael A. Alcorn
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv("repdata.tab", sep = "\t", index_col = False)
no_law = set(df[df["RTW"] == 0]["state"])
yes_law = set(df[df["RTW"] == 1]["state"])
states_that_changed = list(no_law & yes_law)
states_that_changed.sort()
(rows, cols) = (2, 3)
(f, axarr) = plt.subplots(rows, cols)
for (idx, state) in enumerate(states_that_changed):
state_data = df[df["state"] == state]
law_year = state_data[state_data["RTW"] == 1]["year"].min()
i = idx // cols
j = idx % cols
axarr[i, j].plot(state_data["year"], state_data["rate"])
axarr[i, j].axvline(x = law_year, color = "r")
axarr[i, j].set_title(state)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment