moderndid.core.panel.is_balanced_panel#

moderndid.core.panel.is_balanced_panel(data: Any, idname: str, tname: str) bool[source]#

Check whether the panel is balanced.

A balanced panel has exactly one observation for every unit-period combination. This is a quick Boolean check you can run before passing data to an estimator. If the panel is unbalanced, use make_balanced_panel to drop incomplete units or fill_panel_gaps to insert null rows for the missing pairs.

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:
bool

True if every unit is observed in every period.

See also

make_balanced_panel

Drop units not observed in every period.

diagnose_panel

Full diagnostic battery including balance checks.

Examples

In [1]: from moderndid import is_balanced_panel, load_favara_imbs
   ...: 
   ...: df = load_favara_imbs()
   ...: is_balanced_panel(df, idname="county", tname="year")
   ...: 
Out[1]: False