estout
  1. statsmodels_results
  • estout
  • core
  • utils
  • statsmodels_results
  • linearmodels_results

On this page

  • ynames
  • xnames
  • params
  • tstats
  • pvalues
  • covmat
  • se
  • nobs
  • r2
  • Report an issue

statsmodels_results

Functions that extract and standardize results from statsmodels.api.OLS.fit() objects and statsmodels.api.OLS.fit().get_robustcov_results() objects.

Each function extracts a particular statistic from the results object.

These functions must be consistent across the different statistical packages supported by estout.

For example, if we write functions to extract the F-statistic from the linearmodels and statsmodels packages, these functions must have the same name in the linearmodels_results and statsmodels_results modules. They must also have the same return type.

The names of these functions will be the keys of the dictionary returned by the collect_stats function in the core module.

Exported source
import numpy as np
import pandas as pd
import statsmodels.api as sm

Set up an example dataset and run a few regressions to showcase the functions in this module.

np.random.seed(123)
df = pd.DataFrame(np.random.rand(9,3), 
                  columns=['y','x','z'],
                  index = pd.MultiIndex.from_product([[1,2,3],[1,2,3]], names=['firmid','time'])
                  ).assign(cons = 1)
sm1 = sm.OLS(df['y'], df[['cons','x']]).fit()
sm2 = sm.OLS(df['y'], df[['cons','x','z']]).fit().get_robustcov_results(cov_type='HAC', maxlags=2)

The following functions will extract some key information from the sm1 and sm2 objects.

Note that for results produced by .get_robustcov_results() (the sm2 example), many atributes (e.g. params, tstats, and pvalues) are returned as ndarray not pd.Series.
So we will convert them to pd.Series in the appropriate functions.

These statistics have to have the same name across all ’{package_name}_results’ modules.


source

ynames

 ynames (res)
ynames(sm1)
['y']

source

xnames

 xnames (res)
xnames(sm1)
['cons', 'x']

source

params

 params (res)
params(sm1)
cons    0.507852
x       0.345003
dtype: float64
params(sm2)
cons    0.698578
x       0.571069
z      -0.640497
dtype: float64

source

tstats

 tstats (res)
tstats(sm1)
cons    3.905440
x       1.292246
dtype: float64
tstats(sm2)
cons    21.482641
x        2.848571
z       -3.547016
dtype: float64

source

pvalues

 pvalues (res)
pvalues(sm1)
cons    0.005858
x       0.237293
dtype: float64
pvalues(sm2)
cons    6.638188e-07
x       2.923636e-02
z       1.211566e-02
dtype: float64

source

covmat

 covmat (res)
covmat(sm1)
cons x
cons 0.016910 -0.030531
x -0.030531 0.071278
covmat(sm2)
cons x z
cons 0.001057 0.002529 -0.004205
x 0.002529 0.040190 -0.032507
z -0.004205 -0.032507 0.032607

source

se

 se (res)
se(sm1)
cons    0.130037
x       0.266979
dtype: float64
se(sm2)
cons    0.032518
x       0.200476
z       0.180574
dtype: float64

source

nobs

 nobs (res)
nobs(sm1)
9

source

r2

 r2 (res)
r2(sm1)
0.19260886185799486
  • Report an issue