Skip to main content

Instrumental Variable and Linear Panel models for Python

Project description

Build Status codecov Codacy Badge codebeat badge Code Quality: Python Total Alerts

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 master 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 master.

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.6+, 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.6+

  • NumPy (1.14+)

  • SciPy (1+)

  • pandas (0.22+)

  • statsmodels (0.9+)

  • xarray (0.9+, optional)

  • cython (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.15.4.tar.gz (1.7 MB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.8Windows x86

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

Uploaded CPython 3.8

linearmodels-4.15.4-cp38-cp38-manylinux1_i686.whl (1.4 MB view details)

Uploaded CPython 3.8

linearmodels-4.15.4-cp38-cp38-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

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

Uploaded CPython 3.7mWindows x86

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

Uploaded CPython 3.7m

linearmodels-4.15.4-cp37-cp37m-manylinux1_i686.whl (1.4 MB view details)

Uploaded CPython 3.7m

linearmodels-4.15.4-cp37-cp37m-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

linearmodels-4.15.4-cp36-cp36m-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.6mWindows x86-64

linearmodels-4.15.4-cp36-cp36m-win32.whl (1.6 MB view details)

Uploaded CPython 3.6mWindows x86

linearmodels-4.15.4-cp36-cp36m-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.6m

linearmodels-4.15.4-cp36-cp36m-manylinux1_i686.whl (1.4 MB view details)

Uploaded CPython 3.6m

linearmodels-4.15.4-cp36-cp36m-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: linearmodels-4.15.4.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.6

File hashes

Hashes for linearmodels-4.15.4.tar.gz
Algorithm Hash digest
SHA256 ac720fb2111fcfee27638e284d50f719a163cf885ab167f7936fcf3d4d68f7b9
MD5 ac6c99379ee3203aa026b198e36dce20
BLAKE2b-256 770765fcdd7d20beab6a4b14ef5f34f116fd82140df95840dcac69d676592ffc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.15.4-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for linearmodels-4.15.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 67b69cc574f86989fbd6b93f39436c00abbf09363c35679872ca7eee6fb8278f
MD5 074bb65237d98a112904a4e8513f81a6
BLAKE2b-256 77468abe5105a7935c751a8ada2fc36e3ef75d644d16e0f3d48b3b3fdb0d26ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.15.4-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for linearmodels-4.15.4-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 3c1601708386f16f03fd81dbb00a6ce6fad4fa6185d8480a6a6a8f57f3425591
MD5 09d4680cc3dcb2ce59bf5d5b9c953a2e
BLAKE2b-256 12181d429f4d61ae4825dde39fc1251e4cdf2a132e6bcd1dfb6f4a48a8955c0e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.15.4-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

File hashes

Hashes for linearmodels-4.15.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9f7399083910715e7c17ce1eaa6ec77628c51eaf11817ec0ce796a2af1b43066
MD5 fc2cea8996377dc34b76a73d33cf942f
BLAKE2b-256 533c118ea51c8f62f0829874200c8249ff245bf03d1c028db7c41b2ed1bfd896

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.15.4-cp38-cp38-manylinux1_i686.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

File hashes

Hashes for linearmodels-4.15.4-cp38-cp38-manylinux1_i686.whl
Algorithm Hash digest
SHA256 425becece297e777c7e0e28341c33eb07a06841f74c05ed528ae55b400ef3c36
MD5 4d6b9251935fddb025d6e0ebc1a4794e
BLAKE2b-256 f18a04d6ac3c071c61a4b001dd5b50cef61ecd885261d57324cdeb519feca646

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.15.4-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

File hashes

Hashes for linearmodels-4.15.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 41b151722b9aa750c041991592648f376dc91a7f0863b3068a0b3d9457df84c4
MD5 ce88716556e5191346a8033c1e21d83e
BLAKE2b-256 a6537d9610f665e33adf55be0bbfef85d2235454579b19d4f15df8946b39bac5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.15.4-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5

File hashes

Hashes for linearmodels-4.15.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 b6385c4fdc2e694b94c9e50ae7725ef7c9485f2891f1a7c12976f8dbcb431909
MD5 82a210e4d230b4de9f1fe2f58356075e
BLAKE2b-256 9f3ff2a74b27554c58ea37273e91e3d2879fef6e35e8343ca2be706959acee04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.15.4-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5

File hashes

Hashes for linearmodels-4.15.4-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 a0036306a57f3d2a5114c47aa480a1e0238bc5a5536cfac035f8d2738e833100
MD5 3507005e9806770768b14c5087035907
BLAKE2b-256 c284868c4016d8b79cd421b3545bc8ddd49fc561d6485bb67180e6895f5025e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.15.4-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

File hashes

Hashes for linearmodels-4.15.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 50c55189ad2d1abd544368143f49ae9528b2ecd5b1e21614790bd8ab28b4f71d
MD5 c0dd2b3cc19a0780994653a05b1351c5
BLAKE2b-256 4a0def8f2208b6e7d668d0adad774c7015020a2a8002b253910cbed1b359c7c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.15.4-cp37-cp37m-manylinux1_i686.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

File hashes

Hashes for linearmodels-4.15.4-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 4f57c0ecdb76eec4a459f0063b6260a064b2caac5360091a4034871643b9fd7c
MD5 2a17d9cb07982531cbbe989cd09d1a4c
BLAKE2b-256 508a95817c54c53dd2e619009f2f8ab5a8c1b1d00c8ae2026a63ed07e1176441

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.15.4-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

File hashes

Hashes for linearmodels-4.15.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 aea48559b31abc3b679bc4aba770bbe20ef7e181274a7a1c0fa4a27b8b5c4b88
MD5 3fa118c6503cc154b4d7b12ae1b38008
BLAKE2b-256 8a07fa3eac345aa9afb5a177a10ef0864a687a4a3b0827f5f9d95a57ab17da7d

See more details on using hashes here.

File details

Details for the file linearmodels-4.15.4-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: linearmodels-4.15.4-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

File hashes

Hashes for linearmodels-4.15.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c89b89186afb309bceead3f68ac1b3554332ac8681e88541af460ae75cc043df
MD5 f9c060e9f3bf36ec032f9eba5083d421
BLAKE2b-256 fcceeb057a7886ea55e34c41f0d0846c6efa62ee4731aeee623e53da868dbf28

See more details on using hashes here.

File details

Details for the file linearmodels-4.15.4-cp36-cp36m-win32.whl.

File metadata

  • Download URL: linearmodels-4.15.4-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

File hashes

Hashes for linearmodels-4.15.4-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 e79694f1ae850dde727df25f46ed771f82f1d5293d2d42af4901f48fd1b7a8f8
MD5 24e83b185e6fc3d678d6993dd67de69e
BLAKE2b-256 4d4776bf8a92a02d6ed4e3b7f63ee3eeeb3014e64842f183430088605e014f46

See more details on using hashes here.

File details

Details for the file linearmodels-4.15.4-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: linearmodels-4.15.4-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

File hashes

Hashes for linearmodels-4.15.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0ff784193c6c8cf84bb2fea34c2ff61eb2db6b2acbd37296903e900efddf9c3f
MD5 e4b4de1f838854337c4fb45ab2e5f8f0
BLAKE2b-256 27651c16abb6e2364d6bc002d8aad09bc4096b05eb5dc14117cf006ebd6c935c

See more details on using hashes here.

File details

Details for the file linearmodels-4.15.4-cp36-cp36m-manylinux1_i686.whl.

File metadata

  • Download URL: linearmodels-4.15.4-cp36-cp36m-manylinux1_i686.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

File hashes

Hashes for linearmodels-4.15.4-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 76db2e0e53b0223a9ef11b8604ec55dca3cc1a55cd31ab750b0a437f93d99153
MD5 439946139e9064d41ec190a69235179c
BLAKE2b-256 b29b8dfca590c428f3405243b7d341e9beb58486597d6e1d96897af74822fc28

See more details on using hashes here.

File details

Details for the file linearmodels-4.15.4-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: linearmodels-4.15.4-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

File hashes

Hashes for linearmodels-4.15.4-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f02690aebcc7d851721d920fc2f38555034fa5ef1a1b0526d1dc9250e65466cd
MD5 f9138e3781821322e7889a02e8cc1578
BLAKE2b-256 dea2cbbd856e9549c59a54f1e5ad0252857843fa1625934bcb31f5dd4faaf458

See more details on using hashes here.

Supported by

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