linearmodels.panel.model.PanelOLS.reformat_clusters

PanelOLS.reformat_clusters(clusters: ndarray[tuple[int, ...], dtype[int64]] | PanelData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...]) → PanelData

Reformat cluster variables.

Parameters:
clusters: ndarray[tuple[int, ...], dtype[int64]] | PanelData | ndarray | DataArray | DataFrame | Series | list[Any] | tuple[Any, ...]

Values to use for variance clustering. A 1-d array has one value for each row of dependent, in the order of the rows of dependent. A 2-d array (time by entity), a 3-d array (variable by time by entity), a DataFrame with the time periods as its index and the entities as its columns and a DataArray have a value for each time period and entity. They are placed on the rows of dependent, which need not be balanced: the values of the time periods and entities that dependent does not have are not used.

Returns:

Original data with matching axis and observation dropped where missing in the model data.

Return type:

linearmodels.panel.data.PanelData

Raises:

ValueError – If clusters does not have the numbers of entities and time periods of dependent, or has labels that are not those of dependent in the same order. A value for each time period and entity must have the time periods and entities in the order that the Notes describe. Also if clusters has a missing value for an observation that the model uses, i.e., one that is not dropped because dependent, exog, weights or other_effects has a missing value.

Notes

This is exposed for testing and is not normally needed for estimation

The time periods and entities of a value for each time period and entity are matched to those of dependent in the order in which they first appear in the rows of dependent. If dependent is not balanced and the first entity does not have the first periods, the periods of a panel that is sorted by entity first appear in an order that is not their order in time. The time periods are in order of time then, if the rows of every entity are in order of time (in either direction), and the entities are in the order of their labels if the rows of every time period are in order of the entities. A pandas object or DataArray with labels must have the time periods and entities in this order.

Changed in version 7.1: A value for each time period and entity can be used if dependent is not balanced. It raised IndexError: Boolean index has wrong length. It is placed on the rows of dependent by time period and entity. Earlier versions paired it by position with the rows of dependent, which is right only if the rows are sorted by entity and then time. If they were sorted by time and then entity, an array was attached to the wrong observations without an error, and a pandas object with labels was rejected.