{"id":6703,"library":"linearmodels","title":"linearmodels","description":"linearmodels is a Python library that extends `statsmodels` with advanced econometric models, including Panel data models (Fixed Effects, Random Effects), Instrumental Variable (IV) estimators (2SLS, GMM), Factor Asset Pricing models, and System Regression models (SUR, 3SLS). It is currently at version 7.0 and sees active development with several major/minor releases per year.","status":"active","version":"7.0","language":"en","source_language":"en","source_url":"https://github.com/bashtage/linearmodels","tags":["linear models","regression","instrumental variables","IV","panel","fixed effects","clustered","heteroskedasticity","endogeneity","instruments","statistics","statistical inference","econometrics"],"install":[{"cmd":"pip install linearmodels","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Required runtime environment","package":"python","minimum_version":"3.10"},{"reason":"Numerical operations","package":"numpy","minimum_version":"1.22"},{"reason":"Scientific computing","package":"scipy","minimum_version":"1.8"},{"reason":"Data manipulation and structures","package":"pandas","minimum_version":"1.4"},{"reason":"Core statistical models and formulas","package":"statsmodels","minimum_version":"0.13"},{"reason":"R-style formula parsing","package":"formulaic","minimum_version":"1.0"},{"reason":"High-dimensional fixed effects","package":"pyhdfe","optional":true},{"reason":"Type checking extensions","package":"mypy-extensions","optional":true}],"imports":[{"symbol":"PanelOLS","correct":"from linearmodels import PanelOLS"},{"symbol":"IV2SLS","correct":"from linearmodels.iv import IV2SLS"},{"symbol":"SUR","correct":"from linearmodels.system import SUR"},{"symbol":"PooledOLS","correct":"from linearmodels.panel import PooledOLS"},{"symbol":"RandomEffects","correct":"from linearmodels.panel import RandomEffects"}],"quickstart":{"code":"import numpy as np\nimport pandas as pd\nfrom linearmodels.datasets import grunfeld\nfrom linearmodels.panel import PanelOLS\n\ndata = grunfeld.load_pandas().data\ndata.year = data.year.astype(np.int64)\n# Create a MultiIndex (entity - time) for panel data\ndata = data.set_index(['firm', 'year'])\n\n# Define dependent and independent variables\ndep = data.invest\nexog = data[['value', 'capital']]\n\n# Initialize and fit the PanelOLS model with entity effects\nmod = PanelOLS(dep, exog, entity_effects=True)\nres = mod.fit(cov_type='clustered', cluster_entity=True)\n\nprint(res)","lang":"python","description":"This quickstart demonstrates how to load panel data, structure it for `linearmodels` using a pandas MultiIndex, and fit a basic PanelOLS model with entity fixed effects and clustered standard errors."},"warnings":[{"fix":"Review models created with formulas to ensure variable order is as expected. Explicitly define variable order if sensitive.","message":"Starting with version 5.0, the variable ordering in formulas processed by `from_formula` is preserved as it appears in the formula, rather than being sorted alphabetically. This can lead to changes in coefficient ordering or model interpretation if relying on the previous sorting behavior.","severity":"breaking","affected_versions":"5.0.0 and later (including 7.0)"},{"fix":"Upgrade your environment to meet the new minimum requirements: Python >=3.10, NumPy >=1.22, SciPy >=1.8, pandas >=1.4, statsmodels >=0.13, formulaic >=1.0.","message":"Version 5.0 and 7.0 significantly increased the minimum required versions for Python, NumPy, SciPy, pandas, statsmodels, and formulaic. Older environments may not be compatible.","severity":"breaking","affected_versions":"5.0.0, 7.0.0 and later"},{"fix":"Update `cov_type='cluster'` to `cov_type='clustered'` when specifying clustered standard errors.","message":"The name for clustered covariance was corrected from 'cluster' to 'clustered' in version 7.0. Using the old name will likely result in an error.","severity":"gotcha","affected_versions":"7.0.0 and later"},{"fix":"Ensure `formulaic` is installed and that formulas conform to its expected syntax. Be aware that `linearmodels.future.ordering` is a no-op in 5.0+ and has no effect on variable ordering.","message":"The library transitioned to `formulaic` as the preferred formula parser. While `patsy` might have been implicitly used or supported in older versions, `formulaic` is now the standard for R-style formula parsing.","severity":"gotcha","affected_versions":"4.27.0 and later"},{"fix":"Always ensure your regressor matrix is full rank, especially when using `rank_check=False`. Carefully inspect model output and diagnostics for signs of multicollinearity or rank deficiency.","message":"Estimating models with rank-deficient regressors can lead to unreliable estimates. `linearmodels` includes a rank check by default, but it can be skipped using `rank_check=False`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}