1
$\begingroup$

I'm trying to see if differences-in-differences is appropriate for my use here (a colleague suggested I look into it, but I'm having difficulty figuring out if it applies to my scenario). The scenario is as follows:

I am trying to see whether a policy change has significant effects on the number of deaths due to gun violence across zip codes. I have 2019 and 2020 data by week for 5 areas (named A, B, C, D, E: policy was implemented in Feb 2020). All zip codes were subject to the policy after week 6 of 2020.

The data looks roughly as follows:

area year  wk1   wk2   wk3   wk4   wk5... wk52
A    2019  0     5     10    8     3      10
A    2020  9     8     20    3     2      2
B    2019  1     6     11    3     2      11
B    2020  5     5     2     13    5      2
...

The policy change happens in week 6 of 2020. My questions are as follows:

  1. Who would be my controls in this case? Would it be the 2019 data for each of the 5 zips?
  2. Would the "treated" data be the entire 2020 data for each area?
  3. Would pre-treatment times be weeks 1 through 6 and post-treatment times be weeks 6 through 52?
  4. How do I go about "pairing" areas? These areas are quite disparate in terms of gun violence deaths by week (it looks like areas D and E are affluent and have lower overall deaths). Or does difference-in-differences already account for this?
  5. How would I go about doing this analysis in R?
$\endgroup$
2
  • $\begingroup$ Welcome. The policy impacts all jurisdictions at the same time (i.e., week 6)? $\endgroup$ Mar 25, 2021 at 23:02
  • $\begingroup$ Yes it does (there was a specific date in week 6). $\endgroup$ Mar 26, 2021 at 0:55

1 Answer 1

0
$\begingroup$

I appears you're outside the realm of the classical difference-in-differences (DD) framework. I will tackle each one your questions so you can understand why.

To begin, I recommend reshaping your data into long format. Presently, your weeks span your columns, which isn't typical tidy format. Most software packages require your data to be structured this way. Here is your data frame which I reproduced using fake data:

# A tibble: 4 x 5
  area   year   wk1   wk2   wk3
  <chr> <dbl> <int> <int> <int>
1 A      2019     0     1     3
2 A      2020     2     0     3
3 B      2019     6     1     4
4 B      2020     5     6     1

In practice, you want a column to index time. In other words, you want your weekly observations to run down the rows. Each area/jurisdiction should be observed over 104 weeks, assuming each area/jurisdiction is observed in 2019 and 2020. Here is a quick example of how to restructure your data frame:

df %>%
  pivot_longer(cols = starts_with("wk"), names_to = "week", values_to = "deaths")

# A tibble: 12 x 4
   area   year week  deaths
   <chr> <dbl> <chr>  <int>
 1 A      2019 wk1        0
 2 A      2019 wk2        1
 3 A      2019 wk3        3
 4 A      2020 wk1        2
 5 A      2020 wk2        0
 6 A      2020 wk3        3
 7 B      2019 wk1        6
 8 B      2019 wk2        1
 9 B      2019 wk3        4
10 B      2020 wk1        5
11 B      2020 wk2        6
12 B      2020 wk3        1

Now you have a classic panel data set. It is also wise to concatenate "year-week" into one column; it is helpful once you start to add more and more years.

Who would be my controls in this case? Would it be the 2019 data for each of the 5 zips?

Technically, you do not have a viable control group. The policy impacts all jurisdictions. Thus, all jurisdictions are considered "treated" in this setting.

In general, you should observe two groups (i.e., treatment/control group) before and after the policy. The "treatment group" is comprised of the subset of areas (i.e., zip codes) where the policy was introduced. The "control group" is a separate group of areas where the intervention did not take place. This could be all other areas within a city or county, or a matched sample of zip codes.

Would the "treated" data be the entire 2020 data for each area?

No.

If I understand your question correctly, you want to use the same spatial unit in a previous year as the 'control' area. In this sense, areas serve as controls for themselves. I wouldn't advise this. Suppose all weekly observations specific to "Area A" in 2020 fall within your treatment group. That would mean all weekly observations specific to "Area A" in 2019 fall within your control group. The pre- versus post-treatment time dummy would then 'turn on' (i.e., switch from 0 to 1) in "Area A" from week 6 onward in both years, even though the policy was never in effect in 2019. You wouldn't be modeling 'time' appropriately, in part because all weekly observations in 2019 denote your pre-treatment epoch.

Peruse my answer here which addresses this very issue. In short, we should observe the treatment group and the control group contemporaneously through time. The asynchronous pairing of a jurisdiction with itself in a previous year is voluntarily introducing measurement error into your post-treatment indicator.

Would pre-treatment times be weeks 1 through 6 and post-treatment times be weeks 6 through 52?

Not quite.

The pre-treatment phase is weeks 1–52 in 2019 and weeks 1–5 in 2020. Technically, your pre-treatment epoch is all weeks before the intervention. The post-treatment phase is weeks 6–52 in 2020 or whenever the intervention ends.

How do I go about "pairing" areas? These areas are quite disparate in terms of gun violence deaths by week (it looks like areas D and E are affluent and have lower overall deaths). Or does difference in differences already account for this?

The method accounts for time-constant differences observed across jurisdictions.

How would I go about doing this analysis in R?

The classical DD model is a typical interaction model. Assuming you can get your hands on a subset of areas/jurisdictions never espousing the policy, then the setup is fairly straightforward. Instantiate two indicator variables: one "treatment" indicator and one "time" indicator. The "treatment" indicator equals 1 for zip codes where the policy was introduced, 0 otherwise. The "time" indicator equals 1 starting from the sixth week of 2020 until the end of your panel in both groups, 0 otherwise. The DiD coefficient is the interaction of these two variables in a regression framework.

I recommend modeling gun deaths as a count process. The basic specification is as follows:

glm(outcome ~ treatment * post + controls, family = "poisson", data = ...)

As indicated earlier, you must obtain a subset of non-adopter zip codes if you want to proceed with the classical DD approach. Otherwise, you're restricted to a simple before-versus-after estimator.

But fear not as other methods exist. I would look into the CausalImpact package in R.

$\endgroup$
1
  • $\begingroup$ Wow, this is such a great analysis. Thank you so much! $\endgroup$ Mar 26, 2021 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.