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 null rows for missing pairs.

Unlike make_balanced_panel (which drops incomplete units), this function fills gaps so that every unit appears in every period.

Parameters:
dataDataFrame

Panel data. Accepts any object implementing the Arrow PyCapsule Interface (__arrow_c_stream__), including polars, pandas, pyarrow Table, and cudf DataFrames.

idnamestr

Unit identifier column.

tnamestr

Time period column.

Returns:
DataFrame

Rectangular panel in the same format as data.

See also

scan_gaps

Inspect which pairs are missing before filling.

make_balanced_panel

Drop 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