Skip to content

Commit

Permalink
revise multi-cohort specification
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvalal committed Aug 19, 2024
1 parent 66776bf commit 4bd5a56
Showing 1 changed file with 108 additions and 81 deletions.
189 changes: 108 additions & 81 deletions notebooks/event_study.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Multiple cohorts"
"## Multiple cohorts\n",
"\n",
"Event study, followed by fully interacted (Sunab / Wooldridge) regression."
]
},
{
Expand Down Expand Up @@ -1024,9 +1026,32 @@
" plot_backend=\"lets_plot\", coord_flip=False, )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Eq 6.15 in Wooldridge\n",
"\n",
"$$\n",
"Y_{it} = \\alpha + \n",
"\\overbrace{\n",
"\\lambda_q d_q + \\dots \\lambda_T d_T\n",
"}^{\\text{cohort dummies}} + \n",
"\\overbrace{\n",
"\\sum_{s=2}^T \\theta_s fs_t\n",
"}^{\\text{time dummies}} + \n",
"\\overbrace{\n",
" \\sum_{r=q}^T \\sum_{s=r}^T \\tau_{rs} (d_r fs_t)\n",
"}^{\\text{cohort - time dummies}} + \n",
"\\epsilon_{it}\n",
"$$\n",
"\n",
"Under CCT, we exclude cohort-specific-time-specific effects prior to the treatment ($t<q$), but let each cohort have its own time-specific effect after the treatment."
]
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 63,
"metadata": {},
"outputs": [
{
Expand All @@ -1036,7 +1061,7 @@
"\n",
" Y_it ~\n",
" i(rel_year, cohort_dummy_10, ref = -1.0)+i(rel_year, cohort_dummy_15, ref = -1.0)+i(rel_year, cohort_dummy_20, ref = -1.0)\n",
" | unit_id + time_id\n",
" | first_treated_period + time_id\n",
" \n"
]
},
Expand Down Expand Up @@ -1091,6 +1116,15 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.14.0]:cohort_dummy_15</th>\n",
" <td>0.703550</td>\n",
" <td>0.433488</td>\n",
" <td>1.622998</td>\n",
" <td>1.061730e-01</td>\n",
" <td>-0.151270</td>\n",
" <td>1.558370</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.-16.0]:cohort_dummy_20</th>\n",
" <td>-0.270728</td>\n",
" <td>0.482886</td>\n",
Expand All @@ -1100,40 +1134,40 @@
" <td>0.681502</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.10.0]:cohort_dummy_15</th>\n",
" <td>0.206339</td>\n",
" <td>0.409249</td>\n",
" <td>0.504189</td>\n",
" <td>6.146867e-01</td>\n",
" <td>-0.600683</td>\n",
" <td>1.013360</td>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.16.0]:cohort_dummy_10</th>\n",
" <td>0.710607</td>\n",
" <td>0.404913</td>\n",
" <td>1.754963</td>\n",
" <td>8.080460e-02</td>\n",
" <td>-0.087864</td>\n",
" <td>1.509077</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.5.0]:cohort_dummy_15</th>\n",
" <td>2.573325</td>\n",
" <td>0.347956</td>\n",
" <td>7.395543</td>\n",
" <td>3.842704e-12</td>\n",
" <td>1.887171</td>\n",
" <td>3.259480</td>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.-8.0]:cohort_dummy_20</th>\n",
" <td>-0.699541</td>\n",
" <td>0.502003</td>\n",
" <td>-1.393500</td>\n",
" <td>1.650231e-01</td>\n",
" <td>-1.689469</td>\n",
" <td>0.290387</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.-13.0]:cohort_dummy_20</th>\n",
" <td>-0.319648</td>\n",
" <td>0.467241</td>\n",
" <td>-0.684118</td>\n",
" <td>4.946967e-01</td>\n",
" <td>-1.241027</td>\n",
" <td>0.601731</td>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.5.0]:cohort_dummy_10</th>\n",
" <td>-0.126674</td>\n",
" <td>0.442231</td>\n",
" <td>-0.286442</td>\n",
" <td>7.748374e-01</td>\n",
" <td>-0.998733</td>\n",
" <td>0.745386</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.-2.0]:cohort_dummy_20</th>\n",
" <td>-0.115215</td>\n",
" <td>0.233877</td>\n",
" <td>-0.492633</td>\n",
" <td>6.228149e-01</td>\n",
" <td>-0.576410</td>\n",
" <td>0.345979</td>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.-10.0]:cohort_dummy_20</th>\n",
" <td>-0.025361</td>\n",
" <td>0.485448</td>\n",
" <td>-0.052243</td>\n",
" <td>9.583872e-01</td>\n",
" <td>-0.982643</td>\n",
" <td>0.931920</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.-9.0]:cohort_dummy_20</th>\n",
Expand All @@ -1145,31 +1179,13 @@
" <td>0.911462</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.6.0]:cohort_dummy_15</th>\n",
" <td>2.806033</td>\n",
" <td>0.368064</td>\n",
" <td>7.623770</td>\n",
" <td>9.880985e-13</td>\n",
" <td>2.080227</td>\n",
" <td>3.531839</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.-7.0]:cohort_dummy_10</th>\n",
" <td>-0.795139</td>\n",
" <td>0.459648</td>\n",
" <td>-1.729886</td>\n",
" <td>8.520118e-02</td>\n",
" <td>-1.701545</td>\n",
" <td>0.111267</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.-8.0]:cohort_dummy_10</th>\n",
" <td>-0.647257</td>\n",
" <td>0.466537</td>\n",
" <td>-1.387365</td>\n",
" <td>1.668822e-01</td>\n",
" <td>-1.567248</td>\n",
" <td>0.272734</td>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.2.0]:cohort_dummy_15</th>\n",
" <td>1.947334</td>\n",
" <td>0.282989</td>\n",
" <td>6.881306</td>\n",
" <td>7.540613e-11</td>\n",
" <td>1.389292</td>\n",
" <td>2.505376</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.3.0]:cohort_dummy_15</th>\n",
Expand All @@ -1180,52 +1196,61 @@
" <td>1.591676</td>\n",
" <td>2.863939</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C(rel_year, contr.treatment(base=-1.0))[T.-7.0]:cohort_dummy_20</th>\n",
" <td>-0.865233</td>\n",
" <td>0.495434</td>\n",
" <td>-1.746412</td>\n",
" <td>8.228230e-02</td>\n",
" <td>-1.842208</td>\n",
" <td>0.111742</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Estimate Std. Error \\\n",
"Coefficient \n",
"C(rel_year, contr.treatment(base=-1.0))[T.14.0]... 0.703550 0.433488 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-16.0... -0.270728 0.482886 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.10.0]... 0.206339 0.409249 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.5.0]:... 2.573325 0.347956 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-13.0... -0.319648 0.467241 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-2.0]... -0.115215 0.233877 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.16.0]... 0.710607 0.404913 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-8.0]... -0.699541 0.502003 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.5.0]:... -0.126674 0.442231 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-10.0... -0.025361 0.485448 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-9.0]... -0.040965 0.482986 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.6.0]:... 2.806033 0.368064 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-7.0]... -0.795139 0.459648 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-8.0]... -0.647257 0.466537 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.2.0]:... 1.947334 0.282989 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.3.0]:... 2.227807 0.322589 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-7.0]... -0.865233 0.495434 \n",
"\n",
" t value Pr(>|t|) \\\n",
"Coefficient \n",
"C(rel_year, contr.treatment(base=-1.0))[T.14.0]... 1.622998 1.061730e-01 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-16.0... -0.560646 5.756696e-01 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.10.0]... 0.504189 6.146867e-01 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.5.0]:... 7.395543 3.842704e-12 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-13.0... -0.684118 4.946967e-01 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-2.0]... -0.492633 6.228149e-01 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.16.0]... 1.754963 8.080460e-02 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-8.0]... -1.393500 1.650231e-01 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.5.0]:... -0.286442 7.748374e-01 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-10.0... -0.052243 9.583872e-01 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-9.0]... -0.084816 9.324928e-01 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.6.0]:... 7.623770 9.880985e-13 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-7.0]... -1.729886 8.520118e-02 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-8.0]... -1.387365 1.668822e-01 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.2.0]:... 6.881306 7.540613e-11 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.3.0]:... 6.906023 6.553535e-11 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-7.0]... -1.746412 8.228230e-02 \n",
"\n",
" 2.5% 97.5% \n",
"Coefficient \n",
"C(rel_year, contr.treatment(base=-1.0))[T.14.0]... -0.151270 1.558370 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-16.0... -1.222959 0.681502 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.10.0]... -0.600683 1.013360 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.5.0]:... 1.887171 3.259480 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-13.0... -1.241027 0.601731 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-2.0]... -0.576410 0.345979 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.16.0]... -0.087864 1.509077 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-8.0]... -1.689469 0.290387 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.5.0]:... -0.998733 0.745386 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-10.0... -0.982643 0.931920 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-9.0]... -0.993392 0.911462 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.6.0]:... 2.080227 3.531839 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-7.0]... -1.701545 0.111267 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-8.0]... -1.567248 0.272734 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.3.0]:... 1.591676 2.863939 "
"C(rel_year, contr.treatment(base=-1.0))[T.2.0]:... 1.389292 2.505376 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.3.0]:... 1.591676 2.863939 \n",
"C(rel_year, contr.treatment(base=-1.0))[T.-7.0]... -1.842208 0.111742 "
]
},
"execution_count": 57,
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1235,9 +1260,11 @@
" ff := f\"\"\"\n",
" Y_it ~\n",
" {'+'.join([f\"i(rel_year, {x}, ref = -1.0)\" for x in df_int.filter(like = \"cohort_dummy\", axis = 1).columns])}\n",
" | unit_id + time_id\n",
" | first_treated_period + time_id\n",
" \"\"\" # programmatically create all event X treatment interactions interacted with cohort\n",
")\n",
"# cohort intercepts and time intercepts partialled out\n",
"\n",
"m3 = pf.feols(ff, df_int,\n",
" vcov = {\"CRV1\": \"unit_id\"})\n",
"res = m3.tidy()\n",
Expand All @@ -1255,7 +1282,7 @@
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 62,
"metadata": {},
"outputs": [
{
Expand Down

0 comments on commit 4bd5a56

Please sign in to comment.