Skip to main content

Instrumental Variable and Linear Panel 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 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.15+)
  • SciPy (1.0.1+)
  • pandas (0.23+)
  • statsmodels (0.9+)
  • xarray (0.10+, optional)
  • Cython (0.29.14+, 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.18.tar.gz (2.2 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.18-cp39-cp39-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9Windows x86

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.8Windows x86

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

Uploaded CPython 3.7mWindows x86-64

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

Uploaded CPython 3.7mWindows x86

File details

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

File metadata

  • Download URL: linearmodels-4.18.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0.post20201207 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.5

File hashes

Hashes for linearmodels-4.18.tar.gz
Algorithm Hash digest
SHA256 2cccc0120f071932dae632cea05cab64af80fa06f73bea53870801bf924c8c6c
MD5 e0bfc4ef549863598dfba712efc96af5
BLAKE2b-256 72e6bad8c31bd60fe42d43e7ca6479bf21d04f3eb1f98adbc82bd50189882971

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.18-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.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.0

File hashes

Hashes for linearmodels-4.18-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e5aa190ac062804f87d9e20d5cb639f07262a90b8a3c6e19f8e915747e1534e0
MD5 6058e8eccbe6c61bfb5a4471d3288008
BLAKE2b-256 c7683481cbbcdb42aef4d0defb09e24bf672839f65def55f30f551bfc3bb4ab7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.18-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.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.0

File hashes

Hashes for linearmodels-4.18-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 b4ab7482fecc3ee4d01da600ce55364d3d997d46bc4766a89adc78f9227da431
MD5 c83afcf66ca71b33b02c8bb76645a6c6
BLAKE2b-256 c20fd095510bdc41aeff700c74fb41ef580d3815d4500b849711f3487143676f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.18-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.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.0

File hashes

Hashes for linearmodels-4.18-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6d5251a5f10fbe942d82c1cbe6e712267f2f804c05d54513f7a4eef055c93392
MD5 fba455928c9c00d25b9efb76a4daaf76
BLAKE2b-256 c1d05b5903c564a9c2494629e33d11b1a633713d57d3cf52d2a6e767d4e4df82

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.18-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.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.0

File hashes

Hashes for linearmodels-4.18-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 d90b3a9bdf9601a9f5b36197ab91859f66082d1fb2a050d894ddb02c69cdc2ea
MD5 0664bb8d54cbe9ea04b4c8568c0918b0
BLAKE2b-256 aa99ab4dac9e4e9f100a0ae3ec7d235567fb97c96bdc1c1aefcc2dcc6401e0f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.18-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.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.5

File hashes

Hashes for linearmodels-4.18-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 d99d3fff02e7972df7000acd58b440b040f5e121c6e4e978d5f271b7ffa1b1ae
MD5 16584dee657266866009fbc56e7dada5
BLAKE2b-256 5540a687653a0a4bb7548d49154cb9c2ab3d6f489cb4ba27f11988667906744d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.18-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.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.5

File hashes

Hashes for linearmodels-4.18-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 7b524cf4cca6c01b95a59e0a229df5471306ea08bd857f8772454f80132d8ad8
MD5 81abd71240fce48256fc189f241df563
BLAKE2b-256 d361260cd863284ddfc5b7ba338e981bbccc3c46997e833926498636a862844c

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