Regtables Module

The regtables module houses the Regtable class which facilitates storage, access, and presentation for groups of regression results from statsmodels.

regtables

class finance_byu.regtables.Regtable(regressions, regnames=None, orientation='vertical', stat='tstat', sig=False, sig_lbls={'**': 0.05, '***': 0.01}, bfmt='.3f', sfmt='.2f', rsq=True, nobs=True, intercept_name=None)

Tabular output and storage for sets of statsmodels regression objects.

Parameters:
regressions: list(statsmodels.regression.linear_model.RegressionResultsWrapper)

A list of fitted regression result objects from statsmodels.

regnames: list, optional

A list of names or labels corresponding to the regression result objects provided. The length of regnames must match the length of regressions. Defaults to the dependent variable names for each regression.

orientation: {‘vertical’,’horizontal’}, default = ‘vertical’

Specify whether to have the independent variables on the vertical or horizontal axis of the table.

stat: {‘tstat’,’se’,’pvalues’}, default = ‘tstat’

Specify which statistic to report in table.

sig: {False, ‘stat’,’coeff’}, default = False

Whether to denote statistical significance with ‘*’ or other symbols in table output. Defaults to False, which does not denote significance in tables. If statistical significance is to be denoted with regression coefficients, set sig = ‘coeff’. If statistical significance is to be denoted with the reported statistic, set sig = ‘stat’.

sig_lbls: dict([(symbol,level)]), default = {’***’:0.01,’**’:0.05}

Dictionary containing symbols to signify corresponding significance levels (if sig = True). Defaults to {’***’:0.01,’**’:0.05} which displays ‘***’ with entries which are statistically significant at the \(\alpha=0.01\) level and displays ‘**’ with entries which are statistically significant at the \(\alpha=0.05\) level.

bfmt: str, default = ‘.3f’

Float formatting string for the estimated coefficients.

sfmt: str, default = ‘.2f’

Float formatting string for the stat paramater (e.g., t-statistics or standard errors).

rsq: bool, default = True

Whether or not to display R-squared values in the table.

nobs: bool, default = True

Whether or not to display the number of observations in the table.

intercept_name: str, optional

An optional argument to set a name for regression intercepts in the table.

Attributes:
regressions: list(statsmodels.regression.linear_model.RegressionResultsWrapper)

A list of fitted regression result objects from statsmodels.

regnames: list, optional

A list of names or labels corresponding to the regression result objects provided. The length of regnames must match the length of regressions. Defaults to the dependent variable names for each regression.

orientation: {‘vertical’,’horizontal’}, default = ‘vertical’

Specify whether to have the independent variables on the vertical or horizontal axis of the table.

stat: {‘tstat’,’se’,’pvalues’}, default = ‘tstat’

Specify which statistic to report in table.

sig: {False, ‘stat’,’coeff’}, default = False

Whether to denote statistical significance with ‘*’ or other symbols in table output. Defaults to False, which does not denote significance in tables. If statistical significance is to be denoted with regression coefficients, set sig = ‘coeff’. If statistical significance is to be denoted with the reported statistic, set sig = ‘stat’.

sig_lbls: dict([(symbol,level)]), default = {’***’:0.01,’**’:0.05}

Dictionary containing symbols to signify corresponding significance levels (if sig = True). Defaults to {’***’:0.01,’**’:0.05} which displays ‘***’ with entries which are statistically significant at the \(\alpha=0.01\) level and displays ‘**’ with entries which are statistically significant at the \(\alpha=0.05\) level.

bfmt: str, default = ‘.3f’

Float formatting string for the estimated coefficients.

sfmt: str, default = ‘.2f’

Float formatting string for the stat paramater (e.g., t-statistics or standard errors).

rsq: bool, default = True

Whether or not to display R-squared values in the table.

nobs: bool, default = True

Whether or not to display the number of observations in the table.

intercept_name: str, optional

An optional argument to set a name for regression intercepts in the table.

Methods

render()

Returns the table as a pandas.core.frame.DataFrame object.

to_latex()

Returns the table in LaTeX format. Will likely have options for LaTeX formatting in future releases.

set_reg_names(names)

Sets the names of the regressions (regnames) to the argument (names). This method can also take string arguments which set regnames according to particular conventions. The only currently available such option is ‘num-brackets’ which sets [1],[2],… as names for the regressions.

get_coefficients(orientation=’horizontal’)

Returns a pandas dataframe with numerical values for coefficients (NaN where appropriate). Orientation can either be ‘horizontal’ or ‘vertical’, which specifies on which axis to place the independent variables.

get_tstats(orientation=’horizontal’)

Returns a pandas dataframe with numerical values for t-statistics testing the null hypothesis that coefficients are zero (NaN where appropriate). Orientation can either be ‘horizontal’ or ‘vertical’, which specifies on which axis to place the independent variables.

get_se(orientation=’horizontal’)

Returns a pandas dataframe with numerical values for coefficient standard errors (NaN where appropriate). Orientation can either be ‘horizontal’ or ‘vertical’, which specifies on which axis to place the independent variables.

get_pvalues(orientation=’horizontal’)

Returns a pandas dataframe with numerical values for p-values testing the null hypothesis that coefficients are zero (NaN where appropriate). Orientation can either be ‘horizontal’ or ‘vertical’, which specifies on which axis to place the independent variables.

Examples

>>> from finance_byu.regtables import Regtable
>>> import pandas as pd
>>> import statsmodels.formula.api as smf
>>> import numpy as np
>>>
>>>
>>> df = pd.read_csv('./01-nhanes.csv')
>>> df = df.query("age >= 18 and bmi == bmi")
>>> df = df.reset_index(drop=True)
>>> df['rich'] = df['hincome'] == 15
>>>
>>> regformulas =  ['bmi ~ age',
>>>                 'bmi ~ np.log(age)',
>>>                 'bmi ~ C(gender) + np.log(age)',
>>>                 'bmi ~ C(gender) + C(race) + np.log(age)',
>>>                 'bmi ~ C(gender) + rich + C(gender)*rich + C(race) + np.log(age)',
>>>                 'bmi ~ -1 + np.log(age)',
>>>                 'bmi ~ -1 + C(race) + np.log(age)']
>>> reg = [smf.ols(f,df).fit() for f in regformulas]
>>> tbl = Regtable(reg)
>>> tbl.render()

The code above yields a table which renders nicely in Jupyter notebook. For the sake of documentation, I use the tabulate package to show the format of the table; however, using tabulate is not necessary in Jupyter.

>>> from tabulate import tabulate
>>> r = tbl.render()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|                      | bmi     | bmi     | bmi     | bmi     | bmi     | bmi     | bmi     |
|----------------------|---------|---------|---------|---------|---------|---------|---------|
| Intercept            | 15.679  | 15.972  | 16.033  | 15.798  | 15.949  |         |         |
|                      | (27.87) | (15.81) | (15.27) | (13.83) | (13.87) |         |         |
| age                  | -0.012  |         |         |         |         |         |         |
|                      | (-1.26) |         |         |         |         |         |         |
| gender[M]            |         |         | -0.120  | -0.173  | -0.399  |         |         |
|                      |         |         | (-0.21) | (-0.31) | (-0.67) |         |         |
| gender[M]*rich[True] |         |         |         |         | 1.760   |         |         |
|                      |         |         |         |         | (1.04)  |         |         |
| log(age)             |         | -0.253  | -0.252  | -0.238  | -0.234  | 3.852   | -0.239  |
|                      |         | (-0.93) | (-0.93) | (-0.88) | (-0.86) | (46.01) | (-0.88) |
| race[B]              |         |         |         |         |         |         | 15.713  |
|                      |         |         |         |         |         |         | (14.18) |
| race[H]              |         |         |         | 0.370   | 0.358   |         | 16.081  |
|                      |         |         |         | (0.49)  | (0.47)  |         | (14.45) |
| race[O]              |         |         |         | 1.032   | 1.043   |         | 16.735  |
|                      |         |         |         | (1.27)  | (1.29)  |         | (14.78) |
| race[W]              |         |         |         | -0.455  | -0.410  |         | 15.261  |
|                      |         |         |         | (-0.58) | (-0.52) |         | (13.44) |
| rich[True]           |         |         |         |         | -1.311  |         |         |
|                      |         |         |         |         | (-1.10) |         |         |
| Obs                  | 1000    | 1000    | 1000    | 1000    | 1000    | 1000    | 1000    |
| Rsq                  | 0.00    | 0.00    | 0.00    | 0.00    | 0.01    | 0.68    | 0.00    |

The class defaults to no indications of statistical significance, but parameters can be altered to show significance on coefficients or on statistics.

>>> tbl.sig = 'coeff'
>>> r = tbl.render()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))


|                      | bmi       | bmi       | bmi       | bmi       | bmi       | bmi      | bmi       |
|----------------------|-----------|-----------|-----------|-----------|-----------|----------|-----------|
| Intercept            | 15.679*** | 15.972*** | 16.033*** | 15.798*** | 15.949*** |          |           |
|                      | (27.87)   | (15.81)   | (15.27)   | (13.83)   | (13.87)   |          |           |
| age                  | -0.012    |           |           |           |           |          |           |
|                      | (-1.26)   |           |           |           |           |          |           |
| gender[M]            |           |           | -0.120    | -0.173    | -0.399    |          |           |
|                      |           |           | (-0.21)   | (-0.31)   | (-0.67)   |          |           |
| gender[M]*rich[True] |           |           |           |           | 1.760     |          |           |
|                      |           |           |           |           | (1.04)    |          |           |
| log(age)             |           | -0.253    | -0.252    | -0.238    | -0.234    | 3.852*** | -0.239    |
|                      |           | (-0.93)   | (-0.93)   | (-0.88)   | (-0.86)   | (46.01)  | (-0.88)   |
| race[B]              |           |           |           |           |           |          | 15.713*** |
|                      |           |           |           |           |           |          | (14.18)   |
| race[H]              |           |           |           | 0.370     | 0.358     |          | 16.081*** |
|                      |           |           |           | (0.49)    | (0.47)    |          | (14.45)   |
| race[O]              |           |           |           | 1.032     | 1.043     |          | 16.735*** |
|                      |           |           |           | (1.27)    | (1.29)    |          | (14.78)   |
| race[W]              |           |           |           | -0.455    | -0.410    |          | 15.261*** |
|                      |           |           |           | (-0.58)   | (-0.52)   |          | (13.44)   |
| rich[True]           |           |           |           |           | -1.311    |          |           |
|                      |           |           |           |           | (-1.10)   |          |           |
| Obs                  | 1000      | 1000      | 1000      | 1000      | 1000      | 1000     | 1000      |
| Rsq                  | 0.00      | 0.00      | 0.00      | 0.00      | 0.01      | 0.68     | 0.00      |

The significance can also be displayed on the statistic chosen (t-statistic, standard error, etc.).

>>> tbl.sig = 'stat'
>>> r = tbl.render()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|                      | bmi        | bmi        | bmi        | bmi        | bmi        | bmi        | bmi        |
|----------------------|------------|------------|------------|------------|------------|------------|------------|
| Intercept            | 15.679     | 15.972     | 16.033     | 15.798     | 15.949     |            |            |
|                      | (27.87)*** | (15.81)*** | (15.27)*** | (13.83)*** | (13.87)*** |            |            |
| age                  | -0.012     |            |            |            |            |            |            |
|                      | (-1.26)    |            |            |            |            |            |            |
| gender[M]            |            |            | -0.120     | -0.173     | -0.399     |            |            |
|                      |            |            | (-0.21)    | (-0.31)    | (-0.67)    |            |            |
| gender[M]*rich[True] |            |            |            |            | 1.760      |            |            |
|                      |            |            |            |            | (1.04)     |            |            |
| log(age)             |            | -0.253     | -0.252     | -0.238     | -0.234     | 3.852      | -0.239     |
|                      |            | (-0.93)    | (-0.93)    | (-0.88)    | (-0.86)    | (46.01)*** | (-0.88)    |
| race[B]              |            |            |            |            |            |            | 15.713     |
|                      |            |            |            |            |            |            | (14.18)*** |
| race[H]              |            |            |            | 0.370      | 0.358      |            | 16.081     |
|                      |            |            |            | (0.49)     | (0.47)     |            | (14.45)*** |
| race[O]              |            |            |            | 1.032      | 1.043      |            | 16.735     |
|                      |            |            |            | (1.27)     | (1.29)     |            | (14.78)*** |
| race[W]              |            |            |            | -0.455     | -0.410     |            | 15.261     |
|                      |            |            |            | (-0.58)    | (-0.52)    |            | (13.44)*** |
| rich[True]           |            |            |            |            | -1.311     |            |            |
|                      |            |            |            |            | (-1.10)    |            |            |
| Obs                  | 1000       | 1000       | 1000       | 1000       | 1000       | 1000       | 1000       |
| Rsq                  | 0.00       | 0.00       | 0.00       | 0.00       | 0.01       | 0.68       | 0.00       |

Other characters besides the default stars can be used (including LaTeX in Jupyter) to signify statistical significance. Notice that the significance is still shown on the statistic rather than the coefficient since above the sig parameter was specified to be stat. In the tabulate output, the LaTeX text does not render; however, it will render appropriately in Jupyter notebooks.

>>> tbl.sig_lbls = {'$^a$':0.01,'$^b$':0.05}
>>> r = tbl.render()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|                      | bmi         | bmi         | bmi         | bmi         | bmi         | bmi         | bmi         |
|----------------------|-------------|-------------|-------------|-------------|-------------|-------------|-------------|
| Intercept            | 15.679      | 15.972      | 16.033      | 15.798      | 15.949      |             |             |
|                      | (27.87)$^a$ | (15.81)$^a$ | (15.27)$^a$ | (13.83)$^a$ | (13.87)$^a$ |             |             |
| age                  | -0.012      |             |             |             |             |             |             |
|                      | (-1.26)     |             |             |             |             |             |             |
| gender[M]            |             |             | -0.120      | -0.173      | -0.399      |             |             |
|                      |             |             | (-0.21)     | (-0.31)     | (-0.67)     |             |             |
| gender[M]*rich[True] |             |             |             |             | 1.760       |             |             |
|                      |             |             |             |             | (1.04)      |             |             |
| log(age)             |             | -0.253      | -0.252      | -0.238      | -0.234      | 3.852       | -0.239      |
|                      |             | (-0.93)     | (-0.93)     | (-0.88)     | (-0.86)     | (46.01)$^a$ | (-0.88)     |
| race[B]              |             |             |             |             |             |             | 15.713      |
|                      |             |             |             |             |             |             | (14.18)$^a$ |
| race[H]              |             |             |             | 0.370       | 0.358       |             | 16.081      |
|                      |             |             |             | (0.49)      | (0.47)      |             | (14.45)$^a$ |
| race[O]              |             |             |             | 1.032       | 1.043       |             | 16.735      |
|                      |             |             |             | (1.27)      | (1.29)      |             | (14.78)$^a$ |
| race[W]              |             |             |             | -0.455      | -0.410      |             | 15.261      |
|                      |             |             |             | (-0.58)     | (-0.52)     |             | (13.44)$^a$ |
| rich[True]           |             |             |             |             | -1.311      |             |             |
|                      |             |             |             |             | (-1.10)     |             |             |
| Obs                  | 1000        | 1000        | 1000        | 1000        | 1000        | 1000        | 1000        |
| Rsq                  | 0.00        | 0.00        | 0.00        | 0.00        | 0.01        | 0.68        | 0.00        |

The regression headers can also be easily altered.

>>> tbl.set_reg_names('num-brackets')
>>> r = tbl.render()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|                      | [1]         | [2]         | [3]         | [4]         | [5]         | [6]         | [7]         |
|----------------------|-------------|-------------|-------------|-------------|-------------|-------------|-------------|
| Intercept            | 15.679      | 15.972      | 16.033      | 15.798      | 15.949      |             |             |
|                      | (27.87)$^a$ | (15.81)$^a$ | (15.27)$^a$ | (13.83)$^a$ | (13.87)$^a$ |             |             |
| age                  | -0.012      |             |             |             |             |             |             |
|                      | (-1.26)     |             |             |             |             |             |             |
| gender[M]            |             |             | -0.120      | -0.173      | -0.399      |             |             |
|                      |             |             | (-0.21)     | (-0.31)     | (-0.67)     |             |             |
| gender[M]*rich[True] |             |             |             |             | 1.760       |             |             |
|                      |             |             |             |             | (1.04)      |             |             |
| log(age)             |             | -0.253      | -0.252      | -0.238      | -0.234      | 3.852       | -0.239      |
|                      |             | (-0.93)     | (-0.93)     | (-0.88)     | (-0.86)     | (46.01)$^a$ | (-0.88)     |
| race[B]              |             |             |             |             |             |             | 15.713      |
|                      |             |             |             |             |             |             | (14.18)$^a$ |
| race[H]              |             |             |             | 0.370       | 0.358       |             | 16.081      |
|                      |             |             |             | (0.49)      | (0.47)      |             | (14.45)$^a$ |
| race[O]              |             |             |             | 1.032       | 1.043       |             | 16.735      |
|                      |             |             |             | (1.27)      | (1.29)      |             | (14.78)$^a$ |
| race[W]              |             |             |             | -0.455      | -0.410      |             | 15.261      |
|                      |             |             |             | (-0.58)     | (-0.52)     |             | (13.44)$^a$ |
| rich[True]           |             |             |             |             | -1.311      |             |             |
|                      |             |             |             |             | (-1.10)     |             |             |
| Obs                  | 1000        | 1000        | 1000        | 1000        | 1000        | 1000        | 1000        |
| Rsq                  | 0.00        | 0.00        | 0.00        | 0.00        | 0.01        | 0.68        | 0.00        |

>>> tbl.set_reg_names(['reg'+str(x) for x in range(1,8)])
>>> r = tbl.render()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|                      | reg1        | reg2        | reg3        | reg4        | reg5        | reg6        | reg7        |
|----------------------|-------------|-------------|-------------|-------------|-------------|-------------|-------------|
| Intercept            | 15.679      | 15.972      | 16.033      | 15.798      | 15.949      |             |             |
|                      | (27.87)$^a$ | (15.81)$^a$ | (15.27)$^a$ | (13.83)$^a$ | (13.87)$^a$ |             |             |
| age                  | -0.012      |             |             |             |             |             |             |
|                      | (-1.26)     |             |             |             |             |             |             |
| gender[M]            |             |             | -0.120      | -0.173      | -0.399      |             |             |
|                      |             |             | (-0.21)     | (-0.31)     | (-0.67)     |             |             |
| gender[M]*rich[True] |             |             |             |             | 1.760       |             |             |
|                      |             |             |             |             | (1.04)      |             |             |
| log(age)             |             | -0.253      | -0.252      | -0.238      | -0.234      | 3.852       | -0.239      |
|                      |             | (-0.93)     | (-0.93)     | (-0.88)     | (-0.86)     | (46.01)$^a$ | (-0.88)     |
| race[B]              |             |             |             |             |             |             | 15.713      |
|                      |             |             |             |             |             |             | (14.18)$^a$ |
| race[H]              |             |             |             | 0.370       | 0.358       |             | 16.081      |
|                      |             |             |             | (0.49)      | (0.47)      |             | (14.45)$^a$ |
| race[O]              |             |             |             | 1.032       | 1.043       |             | 16.735      |
|                      |             |             |             | (1.27)      | (1.29)      |             | (14.78)$^a$ |
| race[W]              |             |             |             | -0.455      | -0.410      |             | 15.261      |
|                      |             |             |             | (-0.58)     | (-0.52)     |             | (13.44)$^a$ |
| rich[True]           |             |             |             |             | -1.311      |             |             |
|                      |             |             |             |             | (-1.10)     |             |             |
| Obs                  | 1000        | 1000        | 1000        | 1000        | 1000        | 1000        | 1000        |
| Rsq                  | 0.00        | 0.00        | 0.00        | 0.00        | 0.01        | 0.68        | 0.00        |

The class can also handle horizontal tables. The intercept can also be renamed (in either horizontal or vertical mode).

>>> df2 = pd.DataFrame(np.random.random((nobs,10)))
>>> df2.columns = ['t0_vw','t4_vw','et_vw','t0_ew','t4_ew','et_ew','mktrf','smb','hml','umd']
>>> regformulas2 = ['t0_vw ~ mktrf',
>>>                't0_vw ~ mktrf + smb + hml',
>>>                't0_vw ~ mktrf + smb + hml + umd',
>>>                't4_vw ~ mktrf',
>>>                't4_vw ~ mktrf + smb + hml',
>>>                't4_vw ~ mktrf + smb + hml + umd',
>>>                'et_vw ~ mktrf',
>>>                'et_vw ~ mktrf + smb + hml',
>>>                'et_vw ~ mktrf + smb + hml + umd',
>>>                't0_ew ~ mktrf',
>>>                't0_ew ~ mktrf + smb + hml',
>>>                't0_ew ~ mktrf + smb + hml + umd',
>>>                't4_ew ~ mktrf',
>>>                't4_ew ~ mktrf + smb + hml',
>>>                't4_ew ~ mktrf + smb + hml + umd',
>>>                'et_ew ~ mktrf',
>>>                'et_ew ~ mktrf + smb + hml',
>>>                'et_ew ~ mktrf + smb + hml + umd'
>>>                ]
>>> regnames = ['Small VW','','',
>>>             'Large VW','','',
>>>             'Spread VW','','',
>>>             'Small EW','','',
>>>             'Large EW','','',
>>>             'Spread EW','',''
>>>             ]
>>> reg2 = [smf.ols(f,df2).fit() for f in regformulas2]
>>>
>>> tbl2 = Regtable(reg2,orientation='horizontal',regnames=regnames,sig='coeff',intercept_name='alpha')
>>> r = tbl2.render()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|           | alpha    | mktrf   | smb     | hml     | umd       | Obs   | Rsq   |
|-----------|----------|---------|---------|---------|-----------|-------|-------|
| Small VW  | 0.499*** | -0.006  |         |         |           | 1000  | 0.00  |
|           | (27.89)  | (-0.20) |         |         |           |       |       |
|           | 0.498*** | -0.008  | -0.013  | 0.018   |           | 1000  | 0.00  |
|           | (16.88)  | (-0.25) | (-0.42) | (0.55)  |           |       |       |
|           | 0.541*** | -0.010  | -0.011  | 0.020   | -0.086*** | 1000  | 0.01  |
|           | (16.16)  | (-0.33) | (-0.35) | (0.61)  | (-2.67)   |       |       |
| Large VW  | 0.501*** | -0.011  |         |         |           | 1000  | 0.00  |
|           | (28.39)  | (-0.35) |         |         |           |       |       |
|           | 0.470*** | -0.011  | 0.006   | 0.058   |           | 1000  | 0.00  |
|           | (16.18)  | (-0.35) | (0.18)  | (1.81)  |           |       |       |
|           | 0.476*** | -0.011  | 0.006   | 0.058   | -0.011    | 1000  | 0.00  |
|           | (14.39)  | (-0.36) | (0.19)  | (1.82)  | (-0.36)   |       |       |
| Spread VW | 0.490*** | 0.026   |         |         |           | 1000  | 0.00  |
|           | (27.94)  | (0.86)  |         |         |           |       |       |
|           | 0.514*** | 0.024   | -0.023  | -0.025  |           | 1000  | 0.00  |
|           | (17.82)  | (0.78)  | (-0.74) | (-0.79) |           |       |       |
|           | 0.525*** | 0.024   | -0.022  | -0.024  | -0.022    | 1000  | 0.00  |
|           | (16.00)  | (0.76)  | (-0.72) | (-0.77) | (-0.70)   |       |       |
| Small EW  | 0.486*** | 0.015   |         |         |           | 1000  | 0.00  |
|           | (27.68)  | (0.49)  |         |         |           |       |       |
|           | 0.509*** | 0.012   | -0.027  | -0.015  |           | 1000  | 0.00  |
|           | (17.58)  | (0.40)  | (-0.86) | (-0.49) |           |       |       |
|           | 0.499*** | 0.013   | -0.028  | -0.016  | 0.019     | 1000  | 0.00  |
|           | (15.16)  | (0.42)  | (-0.88) | (-0.50) | (0.61)    |       |       |
| Large EW  | 0.509*** | 0.010   |         |         |           | 1000  | 0.00  |
|           | (29.47)  | (0.33)  |         |         |           |       |       |
|           | 0.544*** | 0.004   | -0.057  | -0.007  |           | 1000  | 0.00  |
|           | (19.14)  | (0.14)  | (-1.85) | (-0.21) |           |       |       |
|           | 0.542*** | 0.004   | -0.057  | -0.007  | 0.003     | 1000  | 0.00  |
|           | (16.77)  | (0.14)  | (-1.85) | (-0.21) | (0.11)    |       |       |
| Spread EW | 0.511*** | -0.027  |         |         |           | 1000  | 0.00  |
|           | (28.49)  | (-0.86) |         |         |           |       |       |
|           | 0.540*** | -0.030  | -0.033  | -0.023  |           | 1000  | 0.00  |
|           | (18.31)  | (-0.96) | (-1.04) | (-0.71) |           |       |       |
|           | 0.538*** | -0.030  | -0.033  | -0.023  | 0.005     | 1000  | 0.00  |
|           | (16.01)  | (-0.95) | (-1.04) | (-0.72) | (0.15)    |       |       |

A different statistic can be used, such as standard error.

>>> tbl2.stat = 'se'
>>> r = tbl2.render()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|           | alpha    | mktrf   | smb    | hml    | umd       | Obs   | Rsq   |
|-----------|----------|---------|--------|--------|-----------|-------|-------|
| Small VW  | 0.499*** | -0.006  |        |        |           | 1000  | 0.00  |
|           | (0.02)   | (0.03)  |        |        |           |       |       |
|           | 0.498*** | -0.008  | -0.013 | 0.018  |           | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |       |       |
|           | 0.541*** | -0.010  | -0.011 | 0.020  | -0.086*** | 1000  | 0.01  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |       |       |
| Large VW  | 0.501*** | -0.011  |        |        |           | 1000  | 0.00  |
|           | (0.02)   | (0.03)  |        |        |           |       |       |
|           | 0.470*** | -0.011  | 0.006  | 0.058  |           | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |       |       |
|           | 0.476*** | -0.011  | 0.006  | 0.058  | -0.011    | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |       |       |
| Spread VW | 0.490*** | 0.026   |        |        |           | 1000  | 0.00  |
|           | (0.02)   | (0.03)  |        |        |           |       |       |
|           | 0.514*** | 0.024   | -0.023 | -0.025 |           | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |       |       |
|           | 0.525*** | 0.024   | -0.022 | -0.024 | -0.022    | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |       |       |
| Small EW  | 0.486*** | 0.015   |        |        |           | 1000  | 0.00  |
|           | (0.02)   | (0.03)  |        |        |           |       |       |
|           | 0.509*** | 0.012   | -0.027 | -0.015 |           | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |       |       |
|           | 0.499*** | 0.013   | -0.028 | -0.016 | 0.019     | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |       |       |
| Large EW  | 0.509*** | 0.010   |        |        |           | 1000  | 0.00  |
|           | (0.02)   | (0.03)  |        |        |           |       |       |
|           | 0.544*** | 0.004   | -0.057 | -0.007 |           | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |       |       |
|           | 0.542*** | 0.004   | -0.057 | -0.007 | 0.003     | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |       |       |
| Spread EW | 0.511*** | -0.027  |        |        |           | 1000  | 0.00  |
|           | (0.02)   | (0.03)  |        |        |           |       |       |
|           | 0.540*** | -0.030  | -0.033 | -0.023 |           | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |       |       |
|           | 0.538*** | -0.030  | -0.033 | -0.023 | 0.005     | 1000  | 0.00  |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |       |       |

It is possible to remove the r-squared and observations columns (or rows in vertical orientation).

>>> tbl2.rsq = False
>>> tbl2.nobs = False
>>> r = tbl2.render()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|           | alpha    | mktrf   | smb    | hml    | umd       |
|-----------|----------|---------|--------|--------|-----------|
| Small VW  | 0.499*** | -0.006  |        |        |           |
|           | (0.02)   | (0.03)  |        |        |           |
|           | 0.498*** | -0.008  | -0.013 | 0.018  |           |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |
|           | 0.541*** | -0.010  | -0.011 | 0.020  | -0.086*** |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |
| Large VW  | 0.501*** | -0.011  |        |        |           |
|           | (0.02)   | (0.03)  |        |        |           |
|           | 0.470*** | -0.011  | 0.006  | 0.058  |           |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |
|           | 0.476*** | -0.011  | 0.006  | 0.058  | -0.011    |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |
| Spread VW | 0.490*** | 0.026   |        |        |           |
|           | (0.02)   | (0.03)  |        |        |           |
|           | 0.514*** | 0.024   | -0.023 | -0.025 |           |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |
|           | 0.525*** | 0.024   | -0.022 | -0.024 | -0.022    |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |
| Small EW  | 0.486*** | 0.015   |        |        |           |
|           | (0.02)   | (0.03)  |        |        |           |
|           | 0.509*** | 0.012   | -0.027 | -0.015 |           |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |
|           | 0.499*** | 0.013   | -0.028 | -0.016 | 0.019     |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |
| Large EW  | 0.509*** | 0.010   |        |        |           |
|           | (0.02)   | (0.03)  |        |        |           |
|           | 0.544*** | 0.004   | -0.057 | -0.007 |           |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |
|           | 0.542*** | 0.004   | -0.057 | -0.007 | 0.003     |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |
| Spread EW | 0.511*** | -0.027  |        |        |           |
|           | (0.02)   | (0.03)  |        |        |           |
|           | 0.540*** | -0.030  | -0.033 | -0.023 |           |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) |           |
|           | 0.538*** | -0.030  | -0.033 | -0.023 | 0.005     |
|           | (0.03)   | (0.03)  | (0.03) | (0.03) | (0.03)    |

The tables can be exported to LaTeX for writing purposes.

>>> print(tbl2.to_latex())

\begin{tabular}{llllll}
\toprule
{} &     alpha &   mktrf &     smb &     hml &     umd \\
\midrule
Small VW  &  0.516*** &  -0.020 &         &         &         \\
          &    (0.02) &  (0.03) &         &         &         \\
          &  0.510*** &  -0.021 &  -0.010 &   0.023 &         \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &         \\
          &  0.517*** &  -0.021 &  -0.010 &   0.022 &  -0.013 \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &  (0.03) \\
Large VW  &  0.499*** &   0.013 &         &         &         \\
          &    (0.02) &  (0.03) &         &         &         \\
          &  0.504*** &   0.012 &  -0.031 &   0.022 &         \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &         \\
          &  0.480*** &   0.010 &  -0.031 &   0.022 &   0.051 \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &  (0.03) \\
Spread VW &  0.519*** &  -0.044 &         &         &         \\
          &    (0.02) &  (0.03) &         &         &         \\
          &  0.536*** &  -0.043 &  -0.021 &  -0.014 &         \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &         \\
          &  0.537*** &  -0.043 &  -0.021 &  -0.014 &  -0.002 \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &  (0.03) \\
Small EW  &  0.510*** &  -0.019 &         &         &         \\
          &    (0.02) &  (0.03) &         &         &         \\
          &  0.481*** &  -0.020 &   0.040 &   0.016 &         \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &         \\
          &  0.496*** &  -0.019 &   0.040 &   0.016 &  -0.031 \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &  (0.03) \\
Large EW  &  0.498*** &   0.018 &         &         &         \\
          &    (0.02) &  (0.03) &         &         &         \\
          &  0.469*** &   0.016 &   0.015 &   0.043 &         \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &         \\
          &  0.466*** &   0.016 &   0.015 &   0.043 &   0.006 \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &  (0.03) \\
Spread EW &  0.485*** &   0.017 &         &         &         \\
          &    (0.02) &  (0.03) &         &         &         \\
          &  0.445*** &   0.015 &   0.037 &   0.043 &         \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &         \\
          &  0.448*** &   0.015 &   0.037 &   0.043 &  -0.006 \\
          &    (0.03) &  (0.03) &  (0.03) &  (0.03) &  (0.03) \\
\bottomrule
\end{tabular}
>>> tbl.sig_lbls = {'***':0.01,'**':0.05}
>>> print(tbl.to_latex())

\begin{tabular}{llllllll}
\toprule
{} &        reg1 &        reg2 &        reg3 &        reg4 &        reg5 &        reg6 &        reg7 \\
                     &             &             &             &             &             &             &             \\
\midrule
Intercept            &      13.945 &      13.416 &      13.220 &      13.597 &      13.685 &             &             \\
                     &  (26.02)*** &  (14.02)*** &  (13.28)*** &  (12.00)*** &  (12.02)*** &             &             \\
age                  &       0.017 &             &             &             &             &             &             \\
                     &      (1.87) &             &             &             &             &             &             \\
gender[M]            &             &             &       0.390 &       0.407 &       0.255 &             &             \\
                     &             &             &      (0.72) &      (0.75) &      (0.44) &             &             \\
gender[M]*rich[True] &             &             &             &             &       1.196 &             &             \\
                     &             &             &             &             &      (0.72) &             &             \\
log(age)             &             &       0.390 &       0.389 &       0.400 &       0.405 &       3.839 &       0.400 \\
                     &             &      (1.52) &      (1.52) &      (1.55) &      (1.57) &  (48.14)*** &      (1.55) \\
race[B]              &             &             &             &             &             &             &      13.813 \\
                     &             &             &             &             &             &             &  (12.61)*** \\
race[H]              &             &             &             &      -0.584 &      -0.558 &             &      13.227 \\
                     &             &             &             &     (-0.76) &     (-0.72) &             &  (12.56)*** \\
race[O]              &             &             &             &       0.033 &       0.084 &             &      13.818 \\
                     &             &             &             &      (0.04) &      (0.11) &             &  (13.22)*** \\
race[W]              &             &             &             &      -1.128 &      -1.112 &             &      12.677 \\
                     &             &             &             &     (-1.46) &     (-1.43) &             &  (11.69)*** \\
rich[True]           &             &             &             &             &      -1.014 &             &             \\
                     &             &             &             &             &     (-0.88) &             &             \\
Obs                  &        1000 &        1000 &        1000 &        1000 &        1000 &        1000 &        1000 \\
Rsq                  &        0.00 &        0.00 &        0.00 &        0.01 &        0.01 &        0.70 &        0.01 \\
\bottomrule
\end{tabular}

Note that this simple method uses the default pandas Styler.to_latex() method. For additional functionality in LaTeX exporting, one can use tbl2.render().style.to_latex().

Numerical regression coefficients can be accessed easily from the class (NaN will be filled in where appropriate).

>>> tbl.get_coefficients()

The above method renders a DataFrame of the following form.

>>> r = tbl.get_coefficients()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|                             |        reg1 |      reg2 |       reg3 |       reg4 |       reg5 |      reg6 |      reg7 |
|-----------------------------|-------------|-----------|------------|------------|------------|-----------|-----------|
| Intercept                   |  15.6795    |  15.9724  |  16.0329   |  15.7979   |  15.9485   | nan       | nan       |
| age                         |  -0.0124134 | nan       | nan        | nan        | nan        | nan       | nan       |
| np.log(age)                 | nan         |  -0.25259 |  -0.252166 |  -0.238004 |  -0.23426  |   3.85228 |  -0.23875 |
| C(gender)[T.M]              | nan         | nan       |  -0.119787 |  -0.173274 |  -0.399451 | nan       | nan       |
| C(race)[T.H]                | nan         | nan       | nan        |   0.370329 |   0.358112 | nan       | nan       |
| C(race)[T.O]                | nan         | nan       | nan        |   1.03249  |   1.04337  | nan       | nan       |
| C(race)[T.W]                | nan         | nan       | nan        |  -0.455193 |  -0.409749 | nan       | nan       |
| rich[T.True]                | nan         | nan       | nan        | nan        |  -1.31136  | nan       | nan       |
| C(gender)[T.M]:rich[T.True] | nan         | nan       | nan        | nan        |   1.76     | nan       | nan       |
| C(race)[B]                  | nan         | nan       | nan        | nan        | nan        | nan       |  15.713   |
| C(race)[H]                  | nan         | nan       | nan        | nan        | nan        | nan       |  16.0809  |
| C(race)[O]                  | nan         | nan       | nan        | nan        | nan        | nan       |  16.7353  |
| C(race)[W]                  | nan         | nan       | nan        | nan        | nan        | nan       |  15.2606  |

It is also easy to access standard errors, p-values, and t-statistics.

>>> r = tbl.get_se()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|                             |         reg1 |       reg2 |       reg3 |       reg4 |       reg5 |       reg6 |       reg7 |
|-----------------------------|--------------|------------|------------|------------|------------|------------|------------|
| Intercept                   |   0.562621   |   1.0103   |   1.04974  |   1.1419   |   1.14962  | nan        | nan        |
| age                         |   0.00985983 | nan        | nan        | nan        | nan        | nan        | nan        |
| np.log(age)                 | nan          |   0.270234 |   0.270371 |   0.270469 |   0.271016 |   0.083718 |   0.270335 |
| C(gender)[T.M]              | nan          | nan        |   0.560722 |   0.56139  |   0.600524 | nan        | nan        |
| C(race)[T.H]                | nan          | nan        | nan        |   0.754114 |   0.754578 | nan        | nan        |
| C(race)[T.O]                | nan          | nan        | nan        |   0.810276 |   0.811222 | nan        | nan        |
| C(race)[T.W]                | nan          | nan        | nan        |   0.783893 |   0.785173 | nan        | nan        |
| rich[T.True]                | nan          | nan        | nan        | nan        |   1.19304  | nan        | nan        |
| C(gender)[T.M]:rich[T.True] | nan          | nan        | nan        | nan        |   1.69765  | nan        | nan        |
| C(race)[B]                  | nan          | nan        | nan        | nan        | nan        | nan        |   1.10778  |
| C(race)[H]                  | nan          | nan        | nan        | nan        | nan        | nan        |   1.11291  |
| C(race)[O]                  | nan          | nan        | nan        | nan        | nan        | nan        |   1.13212  |
| C(race)[W]                  | nan          | nan        | nan        | nan        | nan        | nan        |   1.13571  |
>>> r = tbl.get_pvalues()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|                             |           reg1 |          reg2 |          reg3 |          reg4 |          reg5 |           reg6 |          reg7 |
|-----------------------------|----------------|---------------|---------------|---------------|---------------|----------------|---------------|
| Intercept                   |   6.89444e-127 |   2.06663e-50 |   1.76188e-47 |   6.11979e-40 |   3.98454e-40 | nan            | nan           |
| age                         |   0.208328     | nan           | nan           | nan           | nan           | nan            | nan           |
| np.log(age)                 | nan            |   0.350164    |   0.351218    |   0.37909     |   0.387589    |   4.90753e-249 |   0.377361    |
| C(gender)[T.M]              | nan            | nan           |   0.83088     |   0.75765     |   0.506096    | nan            | nan           |
| C(race)[T.H]                | nan            | nan           | nan           |   0.623479    |   0.635187    | nan            | nan           |
| C(race)[T.O]                | nan            | nan           | nan           |   0.202876    |   0.198683    | nan            | nan           |
| C(race)[T.W]                | nan            | nan           | nan           |   0.561586    |   0.601886    | nan            | nan           |
| rich[T.True]                | nan            | nan           | nan           | nan           |   0.271958    | nan            | nan           |
| C(gender)[T.M]:rich[T.True] | nan            | nan           | nan           | nan           |   0.300115    | nan            | nan           |
| C(race)[B]                  | nan            | nan           | nan           | nan           | nan           | nan            |   9.9641e-42  |
| C(race)[H]                  | nan            | nan           | nan           | nan           | nan           | nan            |   4.21998e-43 |
| C(race)[O]                  | nan            | nan           | nan           | nan           | nan           | nan            |   7.54011e-45 |
| C(race)[W]                  | nan            | nan           | nan           | nan           | nan           | nan            |   6.00461e-38 |

>>> r = tbl.get_tstats()
>>> print(tabulate(r,tablefmt='github',headers=r.columns))

|                             |      reg1 |       reg2 |       reg3 |       reg4 |       reg5 |     reg6 |       reg7 |
|-----------------------------|-----------|------------|------------|------------|------------|----------|------------|
| Intercept                   |  27.8687  |  15.8095   |  15.2732   |  13.8348   |  13.8728   | nan      | nan        |
| age                         |  -1.25899 | nan        | nan        | nan        | nan        | nan      | nan        |
| np.log(age)                 | nan       |  -0.934709 |  -0.932666 |  -0.879966 |  -0.864379 |  46.0149 |  -0.883163 |
| C(gender)[T.M]              | nan       | nan        |  -0.213629 |  -0.308653 |  -0.665171 | nan      | nan        |
| C(race)[T.H]                | nan       | nan        | nan        |   0.491079 |   0.474585 | nan      | nan        |
| C(race)[T.O]                | nan       | nan        | nan        |   1.27424  |   1.28617  | nan      | nan        |
| C(race)[T.W]                | nan       | nan        | nan        |  -0.580682 |  -0.521858 | nan      | nan        |
| rich[T.True]                | nan       | nan        | nan        | nan        |  -1.09918  | nan      | nan        |
| C(gender)[T.M]:rich[T.True] | nan       | nan        | nan        | nan        |   1.03673  | nan      | nan        |
| C(race)[B]                  | nan       | nan        | nan        | nan        | nan        | nan      |  14.1843   |
| C(race)[H]                  | nan       | nan        | nan        | nan        | nan        | nan      |  14.4494   |
| C(race)[O]                  | nan       | nan        | nan        | nan        | nan        | nan      |  14.7823   |
| C(race)[W]                  | nan       | nan        | nan        | nan        | nan        | nan      |  13.4371   |