linearmodels.panel.data.PanelData.demean

PanelData.demean(group: 'entity' | 'time' | 'both', *, return_panel: False) → ndarray[tuple[int, ...], dtype[float64]][source]
PanelData.demean(group: 'entity' | 'time' | 'both' = 'entity', weights: PanelData | None = None, return_panel: True = True, low_memory: bool = False) → PanelData
PanelData.demean(group: 'entity' | 'time' | 'both', weights: PanelData | None, return_panel: False) → ndarray[tuple[int, ...], dtype[float64]]

Demean data by either entity or time group.

Parameters:
group: 'entity' | 'time' | 'both'
group: 'entity' | 'time' | 'both' = 'entity'

Group to use in demeaning. The default is “entity”. The names are not case sensitive.

weights: PanelData | None = None
weights: PanelData | None

Weights to implement weighted averaging. If not provided, the observations have equal weights.

return_panel: False
return_panel: True = True

Flag indicating to return a PanelData object. If False, a 2-d NumPy representation of the panel is returned. The default is True.

low_memory: bool = False

Flag indicating whether to use a low memory implementation that avoids constructing dummy variables. Only relevant when group is “both”. The default is False.

Returns:

Demeaned data according to type. An ndarray if return_panel is False.

Return type:

linearmodels.panel.data.PanelData or numpy.ndarray

Raises:

ValueError – If group is not one of the supported values, or if the level of the index that is used has a missing label.

Notes

If weights are provided, the values returned will be scaled by the square root of the weights so that they can be used in WLS estimation.