Package: linearmodels
Linear ModelsMetricLatest ReleaseContinuous IntegrationCoverageCode QualityCitationLinear (regression) models for Python. Extendsstatsmodelswith Panel regression,
instrumental variable estimators, system estimators and models for
estimating asset prices:Panel models:Fixed effects (maximum two-way)First difference regressionBetween estimator for panel dataPooled regression for panel dataFama-MacBeth estimation of panel modelsHigh-dimensional Regresssion:Absorbing Least SquaresInstrumental Variable estimatorsTwo-stage Least SquaresLimited Information Maximum Likelihoodk-class EstimatorsGeneralized Method of Moments, also with continuously updatingFactor Asset Pricing Models:2- and 3-step estimationTime-series estimationGMM estimationSystem Regression:Seemingly Unrelated Regression (SUR/SURE)Three-Stage Least Squares (3SLS)Generalized Method of Moments (GMM) System EstimationDesigned to work equally well with NumPy, Pandas or xarray data.Panel modelsLikestatsmodelsto include, supports
formulas for specifying models. For example, the classic Grunfeld regression can be
specifiedimportnumpyasnpfromstatsmodels.datasetsimportgrunfelddata=grunfeld.load_pandas().datadata.year=data.year.astype(np.int64)# MultiIndex, entity - timedata=data.set_index(['firm','year'])fromlinearmodelsimportPanelOLSmod=PanelOLS(data.invest,data[['value','capital']],entity_effects=True)res=mod.fit(cov_type='clustered',cluster_entity=True)Models can also be specified using the formula interface.fromlinearmodelsimportPanelOLSmod=PanelOLS.from_formula('invest ~ value + capital + EntityEffects',data)res=mod.fit(cov_type='clustered',cluster_entity=True)The formula interface forPanelOLSsupports the special valuesEntityEffectsandTimeEffectswhich add entity (fixed) and time
effects, respectively.Formula support comes from theformulaicpackage which is a replacement forpatsy.Instrumental Variable ModelsIV regression models can be similarly specified.importnumpyasnpfromlinearmodels.ivimportIV2SLSfromlinearmodels.datasetsimportmrozdata=mroz.load()mod=IV2SLS.from_formula('np.log(wage) ~ 1 + exper + exper ** 2 + [educ ~ motheduc + fatheduc]',data)The expressions in the[ ]indicate endogenous regressors (before~)
and the instruments.InstallingThe latest release can be installed using pippipinstalllinearmodelsThe main branch can be installed by cloning the repo and running setupgitclonehttps://github.com/bashtage/linearmodelscdlinearmodels
pipinstall.DocumentationStable Documentationis
built on every tagged version usingdoctr.Development Documentationis automatically built on every successful build of main.Plan and statusShould eventually add some useful linear model estimators such as panel
regression. Currently only the single variable IV estimators are polished.Linear Instrumental variable estimation -completeLinear Panel model estimation -completeFama-MacBeth regression -completeLinear Factor Asset Pricing -completeSystem regression -completeLinear IV Panel model estimation -not startedDynamic Panel model estimation -not startedRequirementsRunningPython 3.9+NumPy (1.22+)SciPy (1.5+)pandas (1.3+)statsmodels (0.12+)formulaic (0.6.5+)xarray (0.16+, optional)Cython (0.29.37+, optional)Testingpy.testDocumentationsphinxsphinx-immaterialnbsphinxnbconvertnbformatipythonjupyter