reg-tables


Namereg-tables JSON
Version 0.1.33 PyPI version JSON
download
home_pagehttps://www.abarbon.com
SummaryA simple linearmodels extension to run panel regressions with different specifications and export the results in a professional-looking latex table
upload_time2023-07-26 16:43:34
maintainer
docs_urlNone
authorAndrea Barbon, Kirill Kazakov
requires_python>=3.8
licenseMIT
keywords linear models regression table
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Description

A simple [linearmodels](https://pypi.org/project/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

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.abarbon.com",
    "name": "reg-tables",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "Linear models,regression table",
    "author": "Andrea Barbon, Kirill Kazakov",
    "author_email": "andrea.3arbon@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/46/f4/8719256de9cf6da20efa453f89017c8753f94b9c05db935d25e37652cc82/reg_tables-0.1.33.tar.gz",
    "platform": null,
    "description": "## Description\r\n\r\nA simple [linearmodels](https://pypi.org/project/linearmodels/) extension to run panel regressions with different specifications and export the results in a professional-looking latex table\r\n\r\n## Installation\r\n```\r\npip install reg_tables\r\n```\r\n\r\n## Sample Usage\r\n\r\n```python\r\nfrom reg_tables import *\r\n\r\n# Generate Random panel\r\nN = 10**3\r\ndf = pd.DataFrame({\r\n    'x1': np.random.randn(N),\r\n    'x2': np.random.randn(N),\r\n})\r\ndf['entity'] = np.random.randint(0,10,N)\r\ndf['time'  ] = np.random.randint(0,50,N)\r\n\r\n# Generate the `y` variable \r\ndf['y'     ] = 2 * df['x1'] - 0.5 * df['x2'] + np.random.randn(N)\r\n\r\n# Generate the `y2`, with some fixed effects \r\ndf['y2'    ] = df['y'] + (df['entity'] % 3)*10 + np.where(df['time']>10, -50, 0)\r\n\r\n# Set the panel's double-index\r\ndf = df.set_index(['entity', 'time'])\r\n\r\n# Define the baseline specification\r\nbaseline = Spec( df, 'y2', ['x1', 'x2'], double_cluster=True )\r\n\r\n# The renaming dictionary\r\nrename   = {\r\n    'y2' : 'Salary',\r\n    'x1' : 'Education',\r\n    'x2' : 'Age',\r\n}\r\n\r\n# Create the model\r\nmodel = Model(baseline, rename_dict=rename)\r\n\r\n# Define some other regression specifications\r\nmodel.add_spec(y='y2', entity_effects=True)\r\nmodel.add_spec(y='y2', time_effects=True)\r\nmodel.add_spec(y='y2', entity_effects=True, time_effects=True)\r\n\r\n# Run all the specifications\r\nres = model.run()\r\nres\r\n```\r\n\r\n\r\n\r\n## Classes and Methods\r\n\r\nThis package consists of two classes: `Spec` and `Model`. \r\n\r\n`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` \u00e2\u20ac\u201c a method to rename variable according to the dictionary passed.\r\n\r\nThe `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.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple linearmodels extension to run panel regressions with different specifications and export the results in a professional-looking latex table",
    "version": "0.1.33",
    "project_urls": {
        "Download": "https://github.com/AndreaBarbon/reg_tables/archive/refs/tags/0.0.5.tar.gz",
        "Homepage": "https://www.abarbon.com"
    },
    "split_keywords": [
        "linear models",
        "regression table"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46f48719256de9cf6da20efa453f89017c8753f94b9c05db935d25e37652cc82",
                "md5": "4991570854c31a27bb2c6fd5b033233a",
                "sha256": "50e826be7a5d062363cfc70807d5576e8610c44d500ed9d4015cfbabe1f654cd"
            },
            "downloads": -1,
            "filename": "reg_tables-0.1.33.tar.gz",
            "has_sig": false,
            "md5_digest": "4991570854c31a27bb2c6fd5b033233a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 15754,
            "upload_time": "2023-07-26T16:43:34",
            "upload_time_iso_8601": "2023-07-26T16:43:34.333351Z",
            "url": "https://files.pythonhosted.org/packages/46/f4/8719256de9cf6da20efa453f89017c8753f94b9c05db935d25e37652cc82/reg_tables-0.1.33.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-26 16:43:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AndreaBarbon",
    "github_project": "reg_tables",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "reg-tables"
}
        
Elapsed time: 0.10452s