-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrapsheet-2WFE.html
778 lines (760 loc) · 36.5 KB
/
scrapsheet-2WFE.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.3.340">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>scrapsheet-2wfe</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="scrapsheet-2WFE_files/libs/clipboard/clipboard.min.js"></script>
<script src="scrapsheet-2WFE_files/libs/quarto-html/quarto.js"></script>
<script src="scrapsheet-2WFE_files/libs/quarto-html/popper.min.js"></script>
<script src="scrapsheet-2WFE_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="scrapsheet-2WFE_files/libs/quarto-html/anchor.min.js"></script>
<link href="scrapsheet-2WFE_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="scrapsheet-2WFE_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="scrapsheet-2WFE_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="scrapsheet-2WFE_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="scrapsheet-2WFE_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
</head>
<body class="fullcontent">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<section id="wfe-scrapsheet" class="level1">
<h1>2WFE Scrapsheet</h1>
<ul>
<li><strong>todo</strong>
<ul>
<li>see <span style="color: #990000">{etwfe}</span> vignette for woolridge method</li>
<li>Re-read printed results and compare with corollary descriptions. Try to figure out what the fuck he’s saying
<ul>
<li>I think the two results might conflict in the union/lwage example. What do you do when that happens</li>
</ul></li>
<li>Finish paper examples and see what his conclusions are</li>
<li>Run on data of first example (newpapers) and see if it’s also close</li>
<li>add results of pkg to each example
<ul>
<li>they don’t match the paper, but they’re close. Could be just rounding errors</li>
</ul></li>
<li>Organize this first section as notes on the Heiss/Jakiela article</li>
<li>Choose what’s going into note in Papers notebook and what stays here in the TWFE section</li>
<li>Maybe email the bastard that made that pkg</li>
<li><a href="https://twitter.com/paulgp/status/1534169803388293120">THREAD</a> +paper, biased estimates for multi-treatment with saturated group adjustment variables</li>
</ul></li>
<li>Two-way fixed effects estimators with heterogeneous treatment effects
<ul>
<li>author: Chaisemartin</li>
<li>paper: <a href="https://arxiv.org/pdf/1803.08807.pdf">arxiv</a></li>
<li>data: <a href="https://www.openicpsr.org/openicpsr/project/118363/version/V2/view?path=/openicpsr/118363/fcr:versions/V2&type=project">website</a></li>
<li>conditional on all treatments, the absolute value of the expectation of βfe divided by the standard deviation of the weights is equal to the minimal value of the standard deviation of the ATEs across the treated (g, t) cells under which the average treatment effect on the treated (ATT) may actually have the opposite sign than that coefficient. One can estimate that ratio to assess the robustness of the two-way FE coefficient. If that ratio is close to 0, that coefficient and the ATT can be of opposite signs even under a small and plausible amount of treatment effect heterogeneity. In that case, treatment effect heterogeneity would be a serious concern for the validity of that coefficient. On the contrary, if that ratio is very large, that coefficient and the ATT can only be of opposite signs under a very large and implausible amount of treatment effect heterogeneity</li>
<li>first difference regression
<ul>
<li>βfd is ATE from period i-1 to i</li>
<li>The outcome variable Y has been first differenced</li>
<li>With group and period control variables</li>
</ul></li>
<li>assumptions
<ul>
<li>assume that Ng,t/Ng,t−1 does not vary across g
<ul>
<li>all groups experience the same growth of their number of observations from t − 1 to t, a requirement that is for instance satisfied when the data is a balanced panel</li>
</ul></li>
</ul></li>
<li>Notation
<ul>
<li>For every (g, t) ∈ {1, …, G} × {1, …, T}, let
<ul>
<li><strong>Ng,t</strong> denote the number of observations in <strong>group g</strong> at <strong>period t</strong></li>
</ul></li>
<li>For every y (i, g, t) ∈ {1, …, Ng,t}×{1, …, G}×{1, …, T}, let
<ul>
<li><strong>Di,g,t</strong> denote treatment status of <strong>observation/unit i</strong> in group g at period t</li>
<li><strong>(Yi,g,t(0), Yi,g,t(1))</strong> denote the potential outcomes without and with treatment of observation i in group g at period t</li>
</ul></li>
<li>The outcome of observation i in group g and period t is <strong>Yi,g,t = Yi,g,t(Di,g,t</strong>).</li>
<li><strong>Dg,t</strong> denotes the average treatment in group g at period t</li>
<li><strong>Yg,t(0)</strong> denotes average potential outcomes without treatment in group g at period t.</li>
<li><strong>Yg,t(1)</strong> denotes average potential outcomes with treatment in group g at period t.</li>
<li><strong>Yg,t</strong>denotes the average observed outcome in group g at period t.</li>
<li><strong>Ng,.</strong> = Σ(t = 1 to T) Ng,t denote the total number of observations in group g</li>
<li><strong>N.,t</strong> = Σ(g =1 to G) Ng,t denote the total number of observations in period t</li>
<li><strong>N1</strong> is the number of treated units</li>
<li><strong>Xg,.</strong> = Σ(t = 1 to T) (Ng,t/Ng,.)Xg,t denote the average value of Xg,t in group g
<ul>
<li>Similar for <strong>X.,t</strong> and <strong>Xg,t</strong></li>
</ul></li>
<li><strong>∆TR</strong> average treatment effect (<strong>ATE</strong>) across all treated units
<ul>
<li><strong>δTR</strong> = E[∆TR]denotes the expectation of that parameter, referred to as the average treatment on the treated (<strong>ATT)</strong>
<ul>
<li><strong>δTR</strong> and <strong>βfe</strong> are both equal to the expectation of a weighted average of the treated cells’ ∆g,ts</li>
</ul></li>
</ul></li>
<li><strong>∆g,t</strong> the <strong>ATE</strong> in cell (g, t).</li>
<li><strong>wg,t</strong> weight formula on pg 7</li>
<li><strong>Pk</strong> = Σ(i≥k) N(i)/N1
<ul>
<li><strong>N(i)</strong> is the number of observations of treated cell i</li>
<li>k ∈ {1, …, n} where n is the number of treated cells</li>
</ul></li>
<li><strong>Sk</strong> = Σ (i≥k) (N(i)/N1)w(i)</li>
<li><strong>Tk</strong> = Σ (i≥k) (N(i)/N1)w2(i)</li>
</ul></li>
</ul></li>
<li>Robustness Test
<ul>
<li><span style="color: #990000">{TwoWayFEWeights}</span></li>
<li>see page 3, penultimate paragraph of Frenchy paper</li>
<li>|βfe| divided by the standard deviation of the weights</li>
<li>βfe denotes the coefficient of Dg,t</li>
<li>σfe described on pg 11 see 1.
<ul>
<li>Corollary 1a: σfe = |βfe| / σ(<strong>w</strong>)
<ul>
<li>If close to zero, treatment effect heterogeneity would be a serious concern for the validity of βfe
<ul>
<li>says, βfe and true ATE can be of opposite signs even under a small and plausible amount of treatment effect heterogeneity</li>
</ul></li>
<li>Re: formula
<ul>
<li>σ(<strong>w</strong>) = sum over treated cells( [(Ng,t / N1)*(w(g,t) - 1)2]1/2 )</li>
<li>w(g,t) = εg,t / sum over treated cells((Ng,t / N1)* εg,t)</li>
<li>Ng,t / N1 would be the proportion of the proportion of total units of all groups of a cell to treated units of a cell
<ul>
<li>So this should be > 1</li>
</ul></li>
<li>Guess you’d look at the residuals of the fe fit for values of εg,t</li>
<li>This may be extractable from fixest pkg</li>
</ul></li>
</ul></li>
<li>Corollary 1b: σfe = |βfe| / [Ts + Ss2/(1 − Ps)]1/2
<ul>
<li>only defined if at least one of the weights is strictly negative</li>
<li>same interpretation as corollary 1a, if close to 0</li>
</ul></li>
</ul></li>
</ul></li>
<li>Example: Newspapers and Politics
<ul>
<li>regress the on
<ul>
<li>state-year fixed effects and on the</li>
<li>first difference of the number of newspapers available in that county</li>
<li>first-difference of the turnout rate in county g between election years t − 1 and t</li>
</ul></li>
<li>Steps (example from paper)
<ul>
<li>calc βfe
<ul>
<li>−0.0011 (s.e.= 0.0011)</li>
</ul></li>
<li>find number of negative and positive weights attached to βfe
<ul>
<li>6,212 are strictly positive, 4,161 are strictly negative</li>
</ul></li>
<li>Find sd of negative weights
<ul>
<li>negative weights sum to -0.53.</li>
<li>σfe = 3 × 10−4</li>
<li>hmm 0.0011/0.53 doesn’t equal 0.0003 so that not it.</li>
</ul></li>
</ul></li>
</ul></li>
<li>Example: wage and unions
<ul>
<li>variables
<ul>
<li>lwage nr year union</li>
<li>test_random_weights(educ)</li>
</ul></li>
</ul></li>
<li>Stata
<ul>
<li><code>D.</code> / <code>d.</code>
<ul>
<li>first difference</li>
<li><code>2D.</code> is second difference</li>
</ul></li>
<li><code>drop</code>
<ul>
<li>remove variables or observations from the dataset in memory</li>
</ul></li>
<li><code>egen</code> / <code>generate</code>
<ul>
<li>dplyr::mutate</li>
<li>“generate” has abbreviations <code>gen</code> / <code>g</code></li>
<li>“egen” works across groups of variables</li>
</ul></li>
<li><code>encode</code> / <code>decode</code>
<ul>
<li>converts string to numeric and numeric to string respectively</li>
</ul></li>
<li><code>forvalues</code> i=1/5
<ul>
<li>for-loop for i = 1 to i = 5</li>
</ul></li>
<li><code>quietly</code> / <code>qui</code>
<ul>
<li>execute the code without printing the output</li>
</ul></li>
<li><code>return</code> / <code>r</code>
<ul>
<li>returns the result of a calculation</li>
</ul></li>
<li><code>summarize</code> / <code>sum</code>
<ul>
<li>summary statistics</li>
</ul></li>
<li><code>tabulate</code> / <code>tab</code>
<ul>
<li>frequency table</li>
</ul></li>
<li><code>xtset</code> group_var, time_var
<ul>
<li>Tells stata that to treat these as panel variables</li>
</ul></li>
</ul></li>
</ul>
<ol type="1">
<li>comparing contributions (w/o standardizations)</li>
<li>correction factor</li>
<li>Wonder about his cv with time series split.+</li>
</ol>
<p>Notes from Kubinec</p>
<ul>
<li>potential outcomes framework
<ul>
<li>We use a control group to approximate Yit(0) and a treatment group for Yit(1) and we randomize treatment assignment to get an <strong>average</strong> treatment effect.</li>
</ul></li>
<li>sequential ignorability - sequence of data doesn’t matter (i.e. time doesn’t matter (so no autocorrelation within units?))
<ul>
<li>we need this assumption because we can’t randomize treatment/control assignments simultaneously across time points and must randomize sequentially</li>
</ul></li>
<li>Variation - all panel data estimands are combinations of these two basic dimensions of variation (ATEi and ATEt)
<ul>
<li>over-time regression coefficient ( ATEt ) - ATE for each case (or unit) across all time points
<ul>
<li>Preferred by researchers but can never obtain randomization of the same nature over time as we can with a cross-section
<ul>
<li>would require that treatment assignment is independent of the potential outcomes
<ul>
<li>can’t do that kind of random assignment as it involves moving across time, not just space</li>
<li>randomization can happen sequentially but is supposed to be simulaneous
<ul>
<li>not the same thing as a cross-section randomization because randomization won’t happen simultaneously to all observations, introducing potential correlation with time as a confounder if the unit changes over time</li>
</ul></li>
</ul></li>
</ul></li>
<li>often considered to be better because it is thought that there is less heterogeneity in the same unit observed over time but not necessarily true
<ul>
<li>over-time inference could be more faulty than a cross-section, especially if the time periods were quite long, such as a panel with hundreds of years. A cross-section would have less heterogeneity in a given year than the same country compared over 300 years apart.</li>
<li>over-time inference should be most credible when T is of the shortest duration.
<ul>
<li>If we can observed repeated observations of the same unit in and out of treatment status, and those time periods are very close together, then we would have much more reason to believe that the units are comparable and treatment status is ignorable.</li>
</ul></li>
</ul></li>
<li>Makes the most sense to calculate an ATEt for each unit, i, and then average those ATEts for all units, i, to get a more precise estimate of ATEt
<ul>
<li>i.e. <code>group_by(unit) %>% summarize(unit_avg = mean(outcome)) %>% ungroup() %>% summarize(ate_t = mean(unit_avg))</code></li>
<li>This calculation requires the assumption of sequential ignorability since we’re averaging across time points in order to get an unbiased estimate.</li>
</ul></li>
</ul></li>
<li>cross-sectional (between-case) regression coefficient ( ATEi ) - ATE for a cross-section of different units at a given point in time
<ul>
<li>treatment randomization is the typical randomization in non-panel data analysis</li>
<li>i.e. <code>group_by(time_point) %>% summarize(cross_sec_avg = mean(outcome)) %>% ungroup() %>% summarize(ate_i = mean(cross_sec_avg))</code></li>
</ul></li>
</ul></li>
<li>what are the criteria for deciding what is a variable we can manipulate as opposed to just a coefficient from a model without any substantive meaning?
<ul>
<li>He claims, “it has to have some kind of independent existence in the ‘real world.’”
<ul>
<li>He’s talking about the intercept, α. It’s represents a unit doesn’t it? If so, it represents a real thing.</li>
</ul></li>
</ul></li>
</ul>
<p>From Lecture <a href="https://yiqingxu.org/public/panel/lec1_handout.pdf">slides</a></p>
<ul>
<li>The 2WFE estimator under staggered adoption is a weighted average of all possible 2x2 DiD estimators that compare timing groups to each other (timing groups are probably the groups that receive treatment at different times)
<ul>
<li>The weights on the 2x2 DiDs are proportional to timing group sizes and the variance of the treatment dummy in each pair, which is highest for units treated in the middle of the panel.
<ul>
<li>I don’t understand what “variance of the treatment dummy in each pair” means</li>
</ul></li>
<li>Assumptions
<ul>
<li>variance weighted common trends, VWCT = 0
<ul>
<li>generalizes the common trend assumption of DiD to a setting with timing variation</li>
<li>the average of the difference in counterfactural trends between pairs of groups and different time periods using the weights from the previous decomposition, and captures how differential trends map to bias in the ^β estimate</li>
<li>captures the fact that different groups might not have the same underlying trend in outcome dynamics, which biases the (really any) DiD estimate.</li>
</ul></li>
<li>heterogeneity - change in treatment effects over time, ∆ATT = 0
<ul>
<li>weighted sum of the <em>change</em> in treatment effects within each unit’s post-period with respect to another unit’s treatment timing</li>
</ul></li>
</ul></li>
<li>2WFE estimates can be biased due to:
<ul>
<li>presence of time-varying confounders (well-known)</li>
<li>feedback from past outcome (known, but often ignored)</li>
<li>heterogeneous treatment effects (often completely ignored)</li>
</ul></li>
</ul></li>
<li>“2x2” difference-in-difference design, meaning there are two groups, and treatment occurs at a single point in time. Many difference-in-difference applications instead use many groups, and treatments that are implemented at different times (a “rollout” design). Traditionally these models have been estimated using fixed effects for group and time period, i.e. “two-way” fixed effects. However, this approach with difference-in-difference can heavily bias results if treatment effects differ across groups, and alternate estimators are preferred. See <a href="https://www.nber.org/papers/w25018">Goodman-Bacon 2018</a> and <a href="https://papers.ssrn.com/sol3/Papers.cfm?abstract_id=3148250">Callaway and Sant’anna 2019</a>.</li>
<li>In the first period, neither of these groups receive a treatment. So for all intents or purposes, you can assume that they are identical in every single say. In the second period, however, one of the groups receive a treatment (a training program, medicine, or other type of treatment), whereas the other is left “untreated”.<br>
<img src="./qmd/_resources/Econometrics,_Fixed_Effects.resources/image001.png" class="img-fluid">
<ul>
<li>y10 means average outcome for treatment group (1) at time period 0 (should be rows then cols but whatevs)</li>
<li>2 equivalent methods to calculate the DiD Treatment Effect (TE)
<ul>
<li>Estimate the treatment effect by comparing the treated-untreated outcomes difference in the post period to the pre-period outcome difference.</li>
</ul></li>
</ul></li>
</ul>
<pre><code>TT1= (y11-y01) Post-period Treated vs untreated
-(y10-y00) pre -period Treated vs untreated</code></pre>
<ul>
<li><p>Uses the “bias-stability” assumption. That whatever factors explain the difference between treated and untreated outcomes after the treatment, are the same before the treatment. (so they can be eliminated)</p></li>
<li><p>Estimate the TE by comparing the outcome change for the treated group across time to the outcome change experienced by the not-treated group.</p></li>
</ul>
<pre><code>TT2= (y11-y10) Treated Post vs pre
-(y01-y00) Untreated Post vs pre</code></pre>
<ul>
<li><p>Uses “parallel-trends” assumption. That if the treated outcome would have experienced a similar and parallel change in outcome as the untreated units experience, then a double difference would also eliminate them.</p></li>
<li><p>Using a linear model</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">lm</span>(y <span class="sc">~</span> Dtreated_unit <span class="sc">+</span> Dpost_treatment <span class="sc">+</span> Dtreated_unit<span class="sc">*</span>Dpost_treatment, <span class="at">data =</span> somedata)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<ul>
<li><p>“Dtreated_unit” - indicator for treatment (TR = 1 for treatment group)</p></li>
<li><p>“Dpost_treatment” - indicator for time (T = 1 for when treatment is occurring)</p></li>
<li><p>Coefficient on the “Dtreated_unitTRUE:Dpost_treatmentTRUE” interaction term represents the treatment effect.</p></li>
</ul></li>
<li><p>Using two-way fixed effects (TWFE) which is an equivalent formulation to the linear model</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">lm</span>(y <span class="sc">~</span> Dtreat <span class="sc">+</span> <span class="fu">factor</span>(id) <span class="sc">+</span> <span class="fu">factor</span>(period), <span class="at">data =</span> somedata)</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="co"># or</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(fixest)</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a><span class="fu">feols</span>(y <span class="sc">~</span> Dtreat <span class="sc">|</span> id <span class="sc">+</span> period, <span class="at">data =</span> somedata)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
<li><p>The core idea of TWFE is that we can subsume the interaction term of the linear model by adding unit and time fixed effects. A single treatment dummy, “Dtreat,” can then be used to capture the effect of treatment directly.</p>
<ul>
<li>Where before both indicators (“Dtreated_unit”, “Dpost_treatment”) held some information about treatment, now only one variable (“Dtreat”) does.</li>
<li>The TWFE shortcut is especially nice for more complicated panel data settings with multiple units and multiple times periods.</li>
</ul></li>
<li><p>Coefficient on the “Dtreat” represents the treatment effect.</p></li>
<li><p>traditional TWFE model obtains a parameter for TE that is the average of all possible 2x2 designs that could be constructed from the above matrix</p>
<ul>
<li>Example Stepped Design (<a href="https://friosavila.github.io/playingwithstata/main_didmany.html">article</a>)<br>
<img src="./qmd/_resources/Econometrics,_Fixed_Effects.resources/Screenshot%20(775).png" class="img-fluid">
<ul>
<li>1 control group: Never-Treat (NT)</li>
<li>3 treatment groups (G): 1, 2, 3</li>
<li>3 periods: 0, 1, 2, 3</li>
<li>Groups receive treatment in the blue squares</li>
</ul></li>
<li>Treatment Effect (TE) calculations for Group 1 at Period 1, 2, 3<img src="./qmd/_resources/Econometrics,_Fixed_Effects.resources/Screenshot%20(770).png" class="img-fluid">
<ul>
<li>Calculation occurs where there’s only 1 treated cell in 2x2 square (“good design”)</li>
<li>“Bad design” (i.e more that 1 cell that’s treated) may identify the treatment effect if the treatment effect is homogenous across groups</li>
<li>If a never treated group (NT) were not available, it is also possible, and valid given limited information, to use units from other “treated” groups as controls, as long as they have not yet been treated<img src="./qmd/_resources/Econometrics,_Fixed_Effects.resources/image008.png" class="img-fluid"></li>
<li>TE for Groups 2 (left, center) and 3 (right)<img src="./qmd/_resources/Econometrics,_Fixed_Effects.resources/Screenshot%20(771).png" class="img-fluid"></li>
</ul></li>
<li>Test the parallel trends assumption for Group 2<img src="./qmd/_resources/Econometrics,_Fixed_Effects.resources/Screenshot%20(774).png" class="img-fluid">
<ul>
<li>Use a square of cells that don’t contain a treatment square</li>
<li>Calculate TE for this square. Should be (significantly close to ) 0.</li>
<li>Using a cell above a treatment cell tests for “treatment anticipation” which may be the cause if the TE != 0</li>
</ul></li>
<li>Doubly-Robust DiD (DRDiD) - uses robust method for calculating Average Treatment Effect on Treated (ATT)</li>
<li>Calloway and Santa Anna DiD (CSDiD) - TE calculations only occur on “good design” (see above) squares and it applies the DRDiD calculation method on those squares
<ul>
<li><span style="color: #990000">{did}</span></li>
</ul></li>
</ul></li>
</ul>
<p>Notes (<a href="https://andrewcbaker.netlify.app/2019/09/25/difference-in-differences-methodology/">article</a>)</p>
<ul>
<li>Equivalent Treatment Effect (TE) Calculations for Traditional 2x2 DiD
<ul>
<li>Manual - treated unit in period 2 (YT2) and the treated unit in period 1 (YT1), less the same difference in the control unit (YC2− YC1).
<ul>
<li>i.e. TE = (YT2 - YT1) - (YC2− YC1)</li>
<li>If units are clusters of individuals, then Y is a mean of those individuals during those periods (I think)</li>
</ul></li>
<li>Regression<br>
<img src="./qmd/_resources/Econometrics,_Fixed_Effects.resources/Screenshot%20(782).png" class="img-fluid">
<ul>
<li>Where POSTt is an indicator for being in the second period and TREATi is an indicator for the treated unit</li>
<li>TE = δ the coefficient of the interaction</li>
</ul></li>
</ul></li>
<li>2wfe<br>
<img src="./qmd/_resources/Econometrics,_Fixed_Effects.resources/Screenshot%20(794).png" class="img-fluid"></li>
<li><ul>
<li>When the treatment effects do not change over time (homogeneous), βDD is the variance-weighted average of cross-group treatment effects, and all of the weights are positive.</li>
<li>When the treatment effect does vary across time (heterogeneous), some of these 2x2 estimates enter the average with negative weights.
<ul>
<li>This is because already-treated units act as controls, and changes in a portion of their treatment effects over time are subtracted from the DiD estimate.</li>
</ul></li>
<li>Question
<ul>
<li>Statement: ^β2x2,k only uses group l’s pre-period, so it’s sample share is (nk+nl)(1−Dl), while ^β2x2,l, uses group k’s post-period, so it’s share is (nk+nl)Dk.
<ul>
<li><p>If there are 3 periods (pre, mid, post), it’s saying the effect calculated from the 2x2 in</p>
<ul>
<li>chart C only uses 33% of the “late” group (green) observations</li>
<li>chart D uses 66% of the “early” group (red) observartions</li>
</ul></li>
<li><h2 id="it-must-have-something-to-do-with-the-model-isnt-smart-and-something-with-indicator-variable-showing-treatment-in-3-out-of-4-of-the-2x2-cells-in-d-and-1-out-of-4-of-the-2x2-cells-in-c-but-i-dont-understand-how-that-translates-to-the-usage-of-observations-in-the-statement" class="anchored" data-anchor-id="wfe-scrapsheet">It must have something to do with the model isn’t “smart” and something with indicator variable showing treatment in 3 out of 4 of the 2x2 cells in D and 1 out of 4 of the 2x2 cells in C but I don’t understand how that translates to the <em>usage</em> of observations in the statement</h2></li>
</ul></li>
</ul></li>
</ul></li>
</ul>
<table class="table">
<colgroup>
<col style="width: 14%">
<col style="width: 14%">
<col style="width: 14%">
<col style="width: 14%">
<col style="width: 14%">
<col style="width: 14%">
<col style="width: 14%">
</colgroup>
<tbody>
<tr class="odd">
<td>model</td>
<td>estimate</td>
<td>se</td>
<td>pval</td>
<td>groups</td>
<td>description</td>
<td></td>
</tr>
<tr class="even">
<td>happiness ~ age</td>
<td>0.1151</td>
<td>0.0121</td>
<td>2.96e-09 ***</td>
<td></td>
<td>pooled estimator</td>
<td></td>
</tr>
<tr class="odd">
<td>happiness ~ age + cohort</td>
<td>0.03687</td>
<td>0.01512</td>
<td>0.0237 *</td>
<td>2 groups</td>
<td></td>
<td></td>
</tr>
<tr class="even">
<td>happiness ~ age + idname</td>
<td>-0.14824</td>
<td>0.01742</td>
<td>1.56e-07 ***</td>
<td>7 groups</td>
<td>within estimator: compares different periods within the same person and discards the between-person variance</td>
<td>plm: effect = “individual”, model = “within”<br>or<br>lm(happiness ~ age + idname, data = df)</td>
</tr>
<tr class="odd">
<td>wage ~ marriage</td>
<td>2066.7</td>
<td>446.4</td>
<td>0.00013 ***</td>
<td></td>
<td>true effect = 500</td>
<td></td>
</tr>
<tr class="even">
<td>wage ~ marriage + id</td>
<td>850.000</td>
<td>84.552</td>
<td>4.834e-09 ***</td>
<td></td>
<td></td>
<td>plm: effect = “individual”, model = “within”</td>
</tr>
</tbody>
</table>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const clipboard = new window.ClipboardJS('.code-copy-button', {
text: function(trigger) {
const codeEl = trigger.previousElementSibling.cloneNode(true);
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>