pyhdfe.Algorithm.residualize¶

Algorithm.
residualize
(matrix, weights=None, errors='raise')¶ Absorb the fixed effects into a matrix and return the residuals from a regression of each column of the matrix on the fixed effects.
Warning
This function assumes that all of your data have already been cleaned. For example, it will not drop observations with null values. It will also not do any checks on provided weights (e.g., if they are all larger than zero).
 Parameters
matrix (arraylike) – The twodimensional array to residualize, which should have a number of rows equal to
Algorithm.observations
(i.e., the number of rows in theids
passed tocreate()
).weights (arraylike, optional) – Twodimensional array with weights, which should have a number of rows equal to
Algorithm.observations
(i.e., the number of rows in theids
passed tocreate()
), and one column. Currently supported algorithms are'within'
,'dummy'
, and nonaccelerated'map'
.errors (str, optional) – If ‘raise’, the default, any errors raise an exception. If ‘warn’, noncritical errors will generate a warning and residualization will continue. For example, if an iteration limit is hit, ‘raise’ will raise an exception, while ‘warn’ will warn that the limit is hit but still return the nonconverged, partially residualized matrix.
 Returns
Residuals from a (potentially weighted) regression of each column of
matrix
on the fixed effects. This matrix has the same number of columns asmatrix
. If any singleton observations were dropped when initializing theAlgorithm
(this is the default behavior ofcreate()
), the residualized matrix will have correspondingly fewer rows. Return type
ndarray
Examples