from _api_doc_utils import *FixedEffectsOLS
Within-estimator for high-dimensional fixed effects
1 Where it fits
Group: Regression
FixedEffectsOLS partials out one or more categorical fixed effects, then runs least squares on residualized variables:
\[ M_F y = M_F X\beta + M_F u. \]
The fixed-effect matrix fe is a 2D uint32 array of zero-based category codes, one column per fixed-effect dimension.
2 Python API
Constructor: cm.FixedEffectsOLS
Call fit(x, fe, y) or fit_weighted(x, fe, y, sample_weight). There is no predict() because the class is estimation-first and does not materialize fixed-effect coefficients. summary() supports the same covariance options as the other linear estimators.
print(inspect.signature(cm.FixedEffectsOLS))()
cls = cm.FixedEffectsOLS
display(HTML(html_table(["Public method"], public_methods(cls))))| Public method |
|---|
bootstrap(self, /, n_bootstrap, seed=None) |
fit(self, /, x, fe, y) |
fit_weighted(self, /, x, fe, y, sample_weight) |
summary(self, /, vcov='hc1', lags=None, clusters=None) |
3 Minimal example
rng = np.random.default_rng(3)
n = 300
x = rng.normal(size=(n, 2))
worker = rng.integers(0, 30, size=n, dtype=np.uint32)
firm = rng.integers(0, 12, size=n, dtype=np.uint32)
fe = np.column_stack([worker, firm]).astype(np.uint32)
y = x @ np.array([0.8, -0.5]) + rng.normal(size=30)[worker] + rng.normal(size=12)[firm] + rng.normal(scale=0.2, size=n)
model = cm.FixedEffectsOLS(); model.fit(x, fe, y)
print(model.summary(vcov="cluster", clusters=worker.astype(np.int64))){'coef': array([ 0.78646351, -0.52522162]), 'coef_se': array([0.01258233, 0.01212151]), 'vcov_type': 'cluster'}
4 summary() contract
The table below is generated by fitting the live class in this repository and then inspecting summary(). Shapes are shown because most values are plain NumPy arrays or scalars.
rng = np.random.default_rng(103)
n=100; x=rng.normal(size=(n,2)); g=rng.integers(0,10,size=n,dtype=np.uint32); h=rng.integers(0,5,size=n,dtype=np.uint32)
fe=np.column_stack([g,h]).astype(np.uint32); y=x@np.array([.8,-.5])+rng.normal(size=10)[g]+rng.normal(size=n)*.2
model=cm.FixedEffectsOLS(); model.fit(x, fe, y)
summary = model.summary()
display(HTML(html_table(["summary() key", "shape"], summary_shape_rows(summary))))| summary() key | shape |
|---|---|
coef |
(2,) |
coef_se |
(2,) |
vcov_type |
() |