Skip to main content

A simple linearmodelsextension to run panel regressions with different specifications and export the results in a professional-looking latex table

Project description

Description

A simple linearmodels extension to run panel regressions with different specifications and export the results in a professional-looking latex table

Installation

pip install reg_tables

Sample Usage

from reg_tables import *

# Generate Random panel
N = 10**3
df = pd.DataFrame({
    'x1': np.random.randn(N),
    'x2': np.random.randn(N),
})
df['entity'] = np.random.randint(0,10,N)
df['time'  ] = np.random.randint(0,50,N)

# Generate the `y` variable 
df['y'     ] = 2 * df['x1'] - 0.5 * df['x2'] + np.random.randn(N)

# Generate the `y2`, with some fixed effects 
df['y2'    ] = df['y'] + (df['entity'] % 3)*10 + np.where(df['time']>10, -50, 0)

# Set the panel's double-index
df = df.set_index(['entity', 'time'])

# Define the baseline specification
baseline = Spec( df, 'y2', ['x1', 'x2'], double_cluster=True )

# The renaming dictionary
rename   = {
    'y2' : 'Salary',
    'x1' : 'Education',
    'x2' : 'Age',
}

# Create the model
model = Model(baseline, rename_dict=rename)

# Define some other regression specifications
model.add_spec(y='y2', entity_effects=True)
model.add_spec(y='y2', time_effects=True)
model.add_spec(y='y2', entity_effects=True, time_effects=True)

# Run all the specifications
res = model.run()
res

Classes and Methods

This package consists of two classes: Spec and Model.

Spec defines the regression specifications, including the panel dataset, the independent variable, and the independent variables. Optional arguments for this class include specifying whether the regressions should be performed with entity effects, time effects or both (entity_effects, time_effects or all_effects arguments respectively). Methods for Spec class include .run, which runs the regression and .rename – a method to rename variable according to the dictionary passed.

The Model class is a wrapper around the compare function of linearmodels. When creating Model, one has to specify the baseline regression specification, passed as a Spec object. Optional arguments include passing a rename_dict, according to which the variables are going to be renamed, as well as setting an all_effects Boolean variable, which will add the four versions of baseline Spec object with all possible combinations of entity and time effects to the model. The Model class has .rename, .add_spec and .remove_spec methods. The latter has a mandatory index argument and second optional index argument, which, if passed would work as a end point for slice. The .run method executes all Spec objects within Model and outputs them to a table. Optional argument coeff_decimals allows to specify the number of decimals for coefficient estimates and t-values, while latex_path allows to save the output table to a disk.

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

reg_tables-0.1.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

reg_tables-0.1.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file reg_tables-0.1.1.tar.gz.

File metadata

  • Download URL: reg_tables-0.1.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.5

File hashes

Hashes for reg_tables-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4991c564ccc2fd69fee931cb971b8d38ea4fd56302884dd4f92c5842a8423c34
MD5 1bc296da04777d8e9fb7cc772633cc21
BLAKE2b-256 b5294245c50ed04277222c4ef7d9c127d509d02e08ddbf9e516aa06582afd568

See more details on using hashes here.

File details

Details for the file reg_tables-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: reg_tables-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.5

File hashes

Hashes for reg_tables-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29bef1a31dbb7ba1254dc211ca5bc0cb5af988b5192bfd621c0e4d6085a07369
MD5 c779909acfb2f04da91ddd10730bd0e1
BLAKE2b-256 dc78107c5cd8f3f0d7b16703ca18a7a3abd5d272d800ffe1880023d3aea83bbc

See more details on using hashes here.

Supported by

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