Skip to main content

Linear Panel, Instrumental Variable, Asset Pricing, and System Regression models for Python

Project description

Linear Models

Metric
Latest Release PyPI version
Continuous Integration Build Status
Build status
Coverage codecov
Code Quality Codacy Badge
codebeat badge
Code Quality: Python
Total Alerts
Citation DOI

Linear (regression) models for Python. Extends statsmodels with Panel regression, instrumental variable estimators, system estimators and models for estimating asset prices:

  • Panel models:

    • Fixed effects (maximum two-way)
    • First difference regression
    • Between estimator for panel data
    • Pooled regression for panel data
    • Fama-MacBeth estimation of panel models
  • High-dimensional Regresssion:

    • Absorbing Least Squares
  • Instrumental Variable estimators

    • Two-stage Least Squares
    • Limited Information Maximum Likelihood
    • k-class Estimators
    • Generalized Method of Moments, also with continuously updating
  • Factor Asset Pricing Models:

    • 2- and 3-step estimation
    • Time-series estimation
    • GMM estimation
  • System Regression:

    • Seemingly Unrelated Regression (SUR/SURE)
    • Three-Stage Least Squares (3SLS)
    • Generalized Method of Moments (GMM) System Estimation

Designed to work equally well with NumPy, Pandas or xarray data.

Panel models

Like statsmodels to include, supports patsy formulas for specifying models. For example, the classic Grunfeld regression can be specified

import numpy as np
from statsmodels.datasets import grunfeld
data = grunfeld.load_pandas().data
data.year = data.year.astype(np.int64)
# MultiIndex, entity - time
data = data.set_index(['firm','year'])
from linearmodels import PanelOLS
mod = 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.

from linearmodels import PanelOLS
mod = PanelOLS.from_formula('invest ~ value + capital + EntityEffects', data)
res = mod.fit(cov_type='clustered', cluster_entity=True)

The formula interface for PanelOLS supports the special values EntityEffects and TimeEffects which add entity (fixed) and time effects, respectively.

Instrumental Variable Models

IV regression models can be similarly specified.

import numpy as np
from linearmodels.iv import IV2SLS
from linearmodels.datasets import mroz
data = 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.

Installing

The latest release can be installed using pip

pip install linearmodels

The main branch can be installed by cloning the repo and running setup

git clone https://github.com/bashtage/linearmodels
cd linearmodels
python setup.py install

Documentation

Stable Documentation is built on every tagged version using doctr. Development Documentation is automatically built on every successful build of main.

Plan and status

Should eventually add some useful linear model estimators such as panel regression. Currently only the single variable IV estimators are polished.

  • Linear Instrumental variable estimation - complete
  • Linear Panel model estimation - complete
  • Fama-MacBeth regression - complete
  • Linear Factor Asset Pricing - complete
  • System regression - complete
  • Linear IV Panel model estimation - not started
  • Dynamic Panel model estimation - not started

Requirements

Running

With the exception of Python 3 (3.7+ tested), which is a hard requirement, the others are the version that are being used in the test environment. It is possible that older versions work.

  • Python 3.7+
  • NumPy (1.15+)
  • SciPy (1.3+)
  • pandas (0.25+)
  • statsmodels (0.11+)
  • xarray (0.13+, optional)
  • Cython (0.29.21+, optional)

Testing

  • py.test

Documentation

  • sphinx
  • sphinx-material
  • nbsphinx
  • nbconvert
  • nbformat
  • ipython
  • jupyter

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linearmodels-4.24.tar.gz (1.8 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

linearmodels-4.24-cp39-cp39-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.9Windows x86-64

linearmodels-4.24-cp39-cp39-win32.whl (1.6 MB view details)

Uploaded CPython 3.9Windows x86

linearmodels-4.24-cp39-cp39-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9

linearmodels-4.24-cp39-cp39-manylinux1_i686.whl (1.5 MB view details)

Uploaded CPython 3.9

linearmodels-4.24-cp39-cp39-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

linearmodels-4.24-cp38-cp38-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.8Windows x86-64

linearmodels-4.24-cp38-cp38-win32.whl (1.6 MB view details)

Uploaded CPython 3.8Windows x86

linearmodels-4.24-cp38-cp38-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.8

linearmodels-4.24-cp38-cp38-manylinux1_i686.whl (1.5 MB view details)

Uploaded CPython 3.8

linearmodels-4.24-cp38-cp38-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

linearmodels-4.24-cp37-cp37m-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.7mWindows x86-64

linearmodels-4.24-cp37-cp37m-win32.whl (1.6 MB view details)

Uploaded CPython 3.7mWindows x86

linearmodels-4.24-cp37-cp37m-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.7m

linearmodels-4.24-cp37-cp37m-manylinux1_i686.whl (1.5 MB view details)

Uploaded CPython 3.7m

linearmodels-4.24-cp37-cp37m-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

Details for the file linearmodels-4.24.tar.gz.

File metadata

  • Download URL: linearmodels-4.24.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for linearmodels-4.24.tar.gz
Algorithm Hash digest
SHA256 397bdfd45c0e8eb3a08674d192580a24eb55b23cded6f747151fbd32715fd887
MD5 b92c6882f8d9708d8b7f37dbdf6347a1
BLAKE2b-256 c004928525e527a7cc3ce8486358d91c69f7bf361fa9b7848f5b62dfc36a7ce4

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: linearmodels-4.24-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for linearmodels-4.24-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ec2af409f6109ea94a5d0bc4bc2b4a4964700945ac65b68f075bdd7a01892e97
MD5 1a39650119206711a897f3102f9200b2
BLAKE2b-256 f081292cf75c175f5ebb3cd478a1686fe883dd867b2949de327164886404f6c0

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp39-cp39-win32.whl.

File metadata

  • Download URL: linearmodels-4.24-cp39-cp39-win32.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for linearmodels-4.24-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 0ba81d5027ac68396d19484eb1aa1cee3efe0eb080154dbb33c651cdb288ddb9
MD5 b7b0e49723855bcefea2c9d8e1044b21
BLAKE2b-256 359da1ce5a6bdd6c6dcb27a7111e8c859f4e0c98f965f5dca8e5ecac3cb521aa

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp39-cp39-manylinux1_x86_64.whl.

File metadata

  • Download URL: linearmodels-4.24-cp39-cp39-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for linearmodels-4.24-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 741bf4420cb6ac2f4d4e6960fd5b44156be3a39aa685b54c18f34b42faf54a79
MD5 8cb5cdf152aed43c3f5ab205fa130f2f
BLAKE2b-256 3babd7afb1dac0c0f4b880459d2778e506b55127cfc800a3f15558885c421fa0

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp39-cp39-manylinux1_i686.whl.

File metadata

  • Download URL: linearmodels-4.24-cp39-cp39-manylinux1_i686.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for linearmodels-4.24-cp39-cp39-manylinux1_i686.whl
Algorithm Hash digest
SHA256 9d31ac0534125da0be8bdf6a7215665a4881bb62a0a92ee63cd463d8efde83f0
MD5 8b2ef38c007301486474290ad99a15b5
BLAKE2b-256 ed9b6a73d81161efa108ac36b326204781886c6f08856289ee7bfc8bd7f588aa

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: linearmodels-4.24-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for linearmodels-4.24-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 65ec0f5858f10e697d293c70ad02483c06245769263856c7cb32ae0379f1799c
MD5 17f2d0959a89b712e9f9784d288b0e40
BLAKE2b-256 10adb46805c51ec3e9a92a026b41338290c063e45a17c04a916e2e8fca5236ed

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: linearmodels-4.24-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.0

File hashes

Hashes for linearmodels-4.24-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 def0d0930156f15e1ee295863013bf88ae30b6326e46238c0373a6ce35aa4e21
MD5 6ddcf076267a8a3b15556a174ac8cd96
BLAKE2b-256 d9465800570b78fbfbdac5bd7a8b82b06ea7d95ef7e253f1915e23b4ee8b1a6f

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp38-cp38-win32.whl.

File metadata

  • Download URL: linearmodels-4.24-cp38-cp38-win32.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.0

File hashes

Hashes for linearmodels-4.24-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 763d1809f0dc85b549104ecbf9b73f6c4a76057883bdf60b12a1c214b6cc15e4
MD5 e9a6ce47e34d59e317abd93635524476
BLAKE2b-256 791990ccaf067d71b9ed00df066d7a1f27fa9dd8b83351fc06c33e5054c29d9f

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: linearmodels-4.24-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for linearmodels-4.24-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7a920779c6fdb525b7526b8f0ddf5b505dda39df4aea84f459bfa35be233417f
MD5 556ae8cca298cc0d19663af6a5839f64
BLAKE2b-256 6bea2d20485757d5031540a28cf902bb656cb18a4182cf33194f809c2015847d

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp38-cp38-manylinux1_i686.whl.

File metadata

  • Download URL: linearmodels-4.24-cp38-cp38-manylinux1_i686.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for linearmodels-4.24-cp38-cp38-manylinux1_i686.whl
Algorithm Hash digest
SHA256 ceeefceaf7065b97d53c64367d72cc73914a64aaf2ea52e23f78d6adfe611d82
MD5 f4d172270fc24e29893ee241067e7b95
BLAKE2b-256 294d71101b8b72b78e7f706fc25b58e9991e7927ce0420722ba5c808ff8bf637

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: linearmodels-4.24-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for linearmodels-4.24-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f0dd7d3f3056241c6ce81d95df573d0bf9c524cf33244caf9cb4b0e32801532f
MD5 2a4e8363c45eebff5800dff37c01982e
BLAKE2b-256 b7079a3b8b79918cd8a720d9d640ca62a2351e58804c7a7deae939fbadd24c9c

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: linearmodels-4.24-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.5

File hashes

Hashes for linearmodels-4.24-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 c9b2d8d01371511cbab64b9493c12664bbc5bdb330ec01fd7eac161f47fb68fd
MD5 8664b8079d9ab908e12637b0df01d137
BLAKE2b-256 30ae7b49b96b315c47cda43b2c0259f999b9f6d65bb24d25626ab1672589e4e1

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp37-cp37m-win32.whl.

File metadata

  • Download URL: linearmodels-4.24-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.5

File hashes

Hashes for linearmodels-4.24-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 c518230f88384c79866aa28f53b4f2d7876e5c164daa5a12eeb40143dd64c1ba
MD5 fefd9c156b23bdf299a5f3434d49d9e5
BLAKE2b-256 090e97e459d746aeec2de48976befa9c2196521db0eb69893b6fa1826d13339c

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: linearmodels-4.24-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10

File hashes

Hashes for linearmodels-4.24-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0fc85d26a1311eeb9ec2edada4de5365cd5663f083d2e64e940668016d039c79
MD5 18e5a9ba23c9a580b26669d3f658a89e
BLAKE2b-256 b2d675c6c953a98edaa85647c8b40a335e541c76a9095767382dee009c01e445

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp37-cp37m-manylinux1_i686.whl.

File metadata

  • Download URL: linearmodels-4.24-cp37-cp37m-manylinux1_i686.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10

File hashes

Hashes for linearmodels-4.24-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 2328a68a553cd8a4c0aebae2bacd4027212bd9ce45621be5d6a6415f774202f3
MD5 d15369fb9b4cf1e019ddbc2154cc1bdd
BLAKE2b-256 6ada77e5f84c796e945fc442191a13dff34f6e35cff7f19e9af883fa9247e90d

See more details on using hashes here.

File details

Details for the file linearmodels-4.24-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: linearmodels-4.24-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10

File hashes

Hashes for linearmodels-4.24-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 97f78097978d4d61b51bb6234b074119a75157a597aa1ddaf5ff285afede3784
MD5 882790c30790f2b0db6c7ffd0555c755
BLAKE2b-256 96e7560e51e493b24eff7fe92f664ce72fe6ecbeb2c87405d89ebf9e804714ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page