import expdpy as ex
from expdpy.data import load_staggered_did, load_staggered_did_data_def
df = ex.set_labels(
load_staggered_did(), load_staggered_did_data_def(), set_panel=True
)
# Panel is declared, so unit=/time= are resolved automatically.
ex.analyze_panel_view(df, cohort="cohort").figanalyze_panel_view
analyze_panel_view(
df,
*,
unit=None,
time=None,
treat=None,
cohort=None,
outcome=None,
never_treated_value=0,
sort_by_timing=True,
max_units=200,
title=None,
)Visualize the treatment structure of a panel (a themed panelview).
Provide either a binary treat column or a first-treatment cohort column (from which the indicator is derived). With outcome given, plots each unit’s outcome over time instead of the treatment quilt.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| df | pd.DataFrame | Long panel data frame. | required |
| unit | str | None | Unit and time identifiers. Default to the declared panel entity and time. | None |
| time | str | None | Unit and time identifiers. Default to the declared panel entity and time. | None |
| treat | str | None | Binary (0/1) treatment-status column. | None |
| cohort | str | None | First-treated period column (used to derive treat when treat is omitted). |
None |
| outcome | str | None | If given, draw an outcome-over-time line per unit instead of the treatment quilt. | None |
| never_treated_value | int | Value of cohort marking never-treated units (default 0). |
0 |
| sort_by_timing | bool | Order units by their first treated period (clearest staggered-adoption picture). | True |
| max_units | int | None | Cap the number of units shown (an even spread is sampled when there are more). | 200 |
| title | str | None | Optional figure title. | None |
Returns
| Name | Type | Description |
|---|---|---|
| PanelViewResult | df (the treatment quilt, or the tidy outcome frame) and fig. |
Examples
Basic — the staggered-adoption treatment quilt (derived from cohort):
Advanced — outcome trajectories per unit instead of the treatment quilt:
import expdpy as ex
from expdpy.data import load_staggered_did, load_staggered_did_data_def
df = ex.set_labels(
load_staggered_did(), load_staggered_did_data_def(), set_panel=True
)
ex.analyze_panel_view(df, cohort="cohort", outcome="outcome").fig