Skip to content

Commit b064e83

Browse files
committed
more TWFE information + references
1 parent 2db2762 commit b064e83

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

docs/source/notebooks/did_pymc_banks.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@
366366
{
367367
"data": {
368368
"application/vnd.jupyter.widget-view+json": {
369-
"model_id": "157d55ed720c45048f1f3b9ec64f1633",
369+
"model_id": "ab6182fae8c348fdb460e76b3a00ff6f",
370370
"version_major": 2,
371371
"version_minor": 0
372372
},
@@ -543,7 +543,7 @@
543543
{
544544
"data": {
545545
"application/vnd.jupyter.widget-view+json": {
546-
"model_id": "e55e1b5eec744b3ab83eb01ce5cd778c",
546+
"model_id": "7101d2c9f94d47d6932c76fa1d2bd42f",
547547
"version_major": 2,
548548
"version_minor": 0
549549
},
@@ -568,7 +568,7 @@
568568
"name": "stderr",
569569
"output_type": "stream",
570570
"text": [
571-
"Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 + 4_000 draws total) took 1 seconds.\n",
571+
"Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 + 4_000 draws total) took 2 seconds.\n",
572572
"Sampling: [beta, sigma, y_hat]\n",
573573
"Sampling: [y_hat]\n",
574574
"Sampling: [y_hat]\n",
@@ -712,7 +712,7 @@
712712
{
713713
"data": {
714714
"application/vnd.jupyter.widget-view+json": {
715-
"model_id": "2765ee0006c8440983f9dcfa938bea5c",
715+
"model_id": "3ee5408d908741fd91fc55eb5e783aab",
716716
"version_major": 2,
717717
"version_minor": 0
718718
},
@@ -737,7 +737,7 @@
737737
"name": "stderr",
738738
"output_type": "stream",
739739
"text": [
740-
"Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 + 4_000 draws total) took 1 seconds.\n",
740+
"Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 + 4_000 draws total) took 2 seconds.\n",
741741
"Sampling: [beta, sigma, y_hat]\n",
742742
"Sampling: [y_hat]\n",
743743
"Sampling: [y_hat]\n",
@@ -831,11 +831,11 @@
831831
"source": [
832832
"## Analysis 4 - Two way fixed effects\n",
833833
"\n",
834-
"Finally, we can evaluate difference in difference model in its two-way fixed effects (TWFE) formulation. \n",
834+
"Finally, we can evaluate the difference in difference model in its two-way fixed effects (TWFE) formulation. The two-way fixed effects model is widely used in econometrics for causal inference in panel data settings. It accounts for both unit-specific effects (e.g., differences between districts) and time-specific effects (e.g., shocks or trends affecting all units simultaneously). \n",
835835
"\n",
836-
"This is similar to the previous model in that the `district:post_treatment` interaction term still gives you a treatment indicator variable and the assiated coefficient $\\beta_{\\Delta}$ is the causal effect of the intervention.\n",
836+
"The TWFE model is equivalent to the classic 2$\\times$2 DiD model (Model 1) - but only in the situation of two groups and two time periods. Outside of this special case the approach is not equivalent and can potentially have some problems {cite:p}`imai2021twfepanel`. Readers should proceed with caution when using the TWFE model outside of the 2$\\times$2 case - see {cite:t}`kropko2018two`.\n",
837837
"\n",
838-
"But it is different in that there is no _linear_ `year` term, instead we have a categorical `year` variable. This means that the model can capture any temporal trends in the data. These can be thought of as capturing time based schocks that affect all units.\n",
838+
"The TWFE approach similar to the previous model in that the `district:post_treatment` interaction term still gives you a treatment indicator variable and the assiated coefficient $\\beta_{\\Delta}$ is the causal effect of the intervention. But it is different in that there is no _linear_ `year` term, instead we have a _categorical_ `year` variable. This means that the model can capture any temporal trends in the data. These can be thought of as capturing time based schocks that affect all units.\n",
839839
"\n",
840840
"The equation for the expected values is:\n",
841841
"\n",
@@ -851,7 +851,7 @@
851851
"* $\\alpha$ is a scalar intercept term.\n",
852852
"* $\\alpha[district_i]$ is a vector of fixed effects for each district. There are only 2 districts, so this is a vector of length 2. The $district_i$ indexes the element of $\\alpha$ that corresponds to the district of the $i^{th}$ observation.\n",
853853
"* $\\beta[year_i]$ is a vector of fixed effects for each year. There are 6 years, so this is a vector of length 6. The $year_i$ indexes the element of $\\beta$ that corresponds to the year of the $i^{th}$ observation.\n",
854-
"* $\\Delta$ is a scalar representing the treatment effect, which is the same as the coefficient of the `district:post_treatment` interaction term.\n"
854+
"* $\\Delta$ is a scalar representing the treatment effect, which is the same as the coefficient of the `district:post_treatment` interaction term."
855855
]
856856
},
857857
{
@@ -875,7 +875,7 @@
875875
{
876876
"data": {
877877
"application/vnd.jupyter.widget-view+json": {
878-
"model_id": "dd5a6855e8034f63961ddd55c6e23e13",
878+
"model_id": "f7899527e56140b29f209c86dd346b38",
879879
"version_major": 2,
880880
"version_minor": 0
881881
},

docs/source/references.bib

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,24 @@ @book{huntington2021effect
126126
year={2021},
127127
publisher={Chapman and Hall/CRC}
128128
}
129+
130+
@article{imai2021twfepanel,
131+
title={On the use of two-way fixed effects regression models for causal inference with panel data},
132+
author={Imai, Kosuke and Kim, In Song},
133+
journal={Political Analysis},
134+
volume={29},
135+
number={3},
136+
pages={405--415},
137+
year={2021},
138+
publisher={Cambridge University Press}
139+
}
140+
141+
@article{kropko2018two,
142+
title={Why the two-way fixed effects model is difficult to interpret, and what to do about it},
143+
author={Kropko, Jonathan and Kubinec, Robert},
144+
journal={Kropko J, Kubinec R (2020) Interpretation and identification of within-unit and cross-sectional variation in panel data models. PLoS ONE},
145+
volume={15},
146+
number={4},
147+
pages={e0231349},
148+
year={2018}
149+
}

0 commit comments

Comments
 (0)