Bergé, L. (2018). Efficient estimation of maximum likelihood models with multiple fixed-effects: the R package FENmlm. CREA Discussion Paper.
Correia, S., Guimaraes, P., & Zylkin, T. (2019). ppmlhdfe: Fast Poisson Estimation with High-Dimensional Fixed Effects. The Stata Journal.
Stammann, A. (2018). Fast and Feasible Estimation of Generalized Linear Models with High-Dimensional k-way Fixed Effects. arXiv:1707.01815.
Parameters
Name
Type
Description
Default
fml
str
A two-sided formula string using fixest formula syntax. Syntax: “Y ~ X1 + X2 | FE1 + FE2”. “|” separates left-hand side and fixed effects. Special syntax includes: - Stepwise regressions (sw, sw0) - Cumulative stepwise regression (csw, csw0) - Multiple dependent variables (Y1 + Y2 ~ X) - Interaction of variables (i(X1,X2)) - Interacted fixed effects (fe1^fe2) Compatible with formula parsing via the formulaic module.
required
data
DataFrameType
A pandas or polars dataframe containing the variables in the formula.
required
family
str
The family of the GLM model. Options include “gaussian”, “logit” and “probit”.
required
vcov
Union[VcovTypeOptions, dict[str, str]]
Type of variance-covariance matrix for inference. Options include “iid”, “hetero”, “HC1”, “HC2”, “HC3”, “NW” for Newey-West HAC standard errors, “DK” for Driscoll-Kraay HAC standard errors, or a dictionary for CRV1/CRV3 inference. Note that NW and DK require to pass additional keyword arguments via the vcov_kwargs argument. For time-series HAC, you need to pass the ‘time_id’ column. For panel-HAC, you need to add pass both ‘time_id’ and ‘panel_id’. See vcov_kwargs for details.
None
vcov_kwargs
Optional[dict[str, any]]
Additional keyword arguments to pass to the vcov function. These keywoards include “lag” for the number of lag to use in the Newey-West (NW) and Driscoll-Kraay (DK) HAC standard errors. “time_id” for the time ID used for NW and DK standard errors, and “panel_id” for the panel identifier used for NW and DK standard errors. Currently, the the time difference between consecutive time periods is always treated as 1. More flexible time-step selection is work in progress.
None
ssc
str
A ssc object specifying the small sample correction for inference.
None
fixef_rm
FixedRmOptions
Specifies whether to drop singleton fixed effects. Can be equal to “singleton” (default), or “none”. “singletons” will drop singleton fixed effects. This will not impact point estimates but it will impact standard errors.
'singleton'
iwls_tol
Optional[float]
Tolerance for IWLS convergence, by default 1e-08.
1e-08
iwls_maxiter
Optional[float]
Maximum number of iterations for IWLS convergence, by default 25.
25
collin_tol
float
Tolerance for collinearity check, by default 1e-10.
1e-09
separation_check
list[str] | None
Methods to identify and drop separated observations. Either “fe” or “ir”. Executes “fe” by default (when None).
None
solver
SolverOptions, optional.
The solver to use for the regression. Can be “np.linalg.lstsq”, “np.linalg.solve”, “scipy.linalg.solve”, “scipy.sparse.linalg.lsqr” and “jax”. Defaults to “scipy.linalg.solve”.
'scipy.linalg.solve'
demeaner
AnyDemeaner | None
Typed demeaner configuration. Controls the fixed-effects demeaning backend, tolerance, and iteration limits. Accepts a MapDemeaner, WithinDemeaner, or LsmrDemeaner instance. Defaults to MapDemeaner() (numba MAP algorithm, tol=1e-6, maxiter=10_000).
None
drop_intercept
bool
Whether to drop the intercept from the model, by default False.
False
copy_data
bool
Whether to copy the data before estimation, by default True. If set to False, the data is not copied, which can save memory but may lead to unintended changes in the input data outside of fepois. For example, the input data set is re-index within the function. As far as I know, the only other relevant case is when using interacted fixed effects, in which case you’ll find a column with interacted fixed effects in the data set.
True
store_data
bool
Whether to store the data in the model object, by default True. If set to False, the data is not stored in the model object, which can improve performance and save memory. However, it will no longer be possible to access the data via the data attribute of the model object. This has impact on post-estimation capabilities that rely on the data, e.g. predict() or vcov().
True
lean
bool
False by default. If True, then all large objects are removed from the returned result: this will save memory but will block the possibility to use many methods. It is recommended to use the argument vcov to obtain the appropriate standard-errors at estimation time, since obtaining different SEs won’t be possible afterwards.
False
context
int or Mapping[str, Any]
A dictionary containing additional context variables to be used by formulaic during the creation of the model matrix. This can include custom factorization functions, transformations, or any other variables that need to be available in the formula environment.
None
split
str | None
A character string, i.e. ‘split = var’. If provided, the sample is split according to the variable and one estimation is performed for each value of that variable. If you also want to include the estimation for the full sample, use the argument fsplit instead.
None
fsplit
str | None
This argument is the same as split but also includes the full sample as the first estimation.
None
accelerate
bool
Whether to use acceleration tricks developed in the ppmlhdfe paper (warm start and adaptive fixed effects tolerance) for models with fixed effects. Produces numerically identical results faster, so we recommend to always set it to True.
Format of coefficient cell: Coefficient (Std. Error)
PyFixest also integrates with the marginaleffects package. To compute average marginal effects for the logit model above:
from marginaleffects import avg_slopesavg_slopes(fit_logit, variables="X1")
shape: (1, 3)
term
contrast
estimate
str
str
f64
"X1"
"dY/dX"
-1.016344
We can also compute marginal effects by group (group average marginal effects):
avg_slopes(fit_logit, variables="X1", by="f1")
shape: (30, 4)
f1
term
contrast
estimate
f64
str
str
f64
0.0
"X1"
"dY/dX"
-1.016344
1.0
"X1"
"dY/dX"
-1.016344
2.0
"X1"
"dY/dX"
-1.016344
3.0
"X1"
"dY/dX"
-1.016344
4.0
"X1"
"dY/dX"
-1.016344
…
…
…
…
25.0
"X1"
"dY/dX"
-1.016344
26.0
"X1"
"dY/dX"
-1.016344
27.0
"X1"
"dY/dX"
-1.016344
28.0
"X1"
"dY/dX"
-1.016344
29.0
"X1"
"dY/dX"
-1.016344
Shared arguments such as vcov, ssc, split, fsplit, context, and typed demeaners work the same way as in feols(). See the feols() reference for those details, and the Marginal Effects guide for a compact post-estimation workflow.