moderndid.core.panel.fill_panel_gaps#
- moderndid.core.panel.fill_panel_gaps(data: Any, idname: str, tname: str) Any[source]#
Make the panel rectangular by inserting
nullrows for missing pairs.Unlike
make_balanced_panel(which drops incomplete units), this function fills gaps so that every unit appears in every period.- Parameters:
- Returns:
DataFrameRectangular panel in the same format as data.
See also
scan_gapsInspect which pairs are missing before filling.
make_balanced_panelDrop incomplete units instead of filling gaps.
Examples
In [1]: from moderndid import fill_panel_gaps, has_gaps, load_favara_imbs ...: ...: df = load_favara_imbs() ...: print(has_gaps(df, idname="county", tname="year")) ...: True In [2]: filled = fill_panel_gaps(df, idname="county", tname="year") ...: print(f"Before: {df.shape[0]} rows, After: {filled.shape[0]} rows") ...: Before: 12538 rows, After: 12576 rows