Exported source
import numpy as np
import pandas as pdstatsmodels.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.
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.
ynames (res)
xnames (res)
params (res)
tstats (res)
pvalues (res)
covmat (res)
| cons | x | z | |
|---|---|---|---|
| cons | 0.001057 | 0.002529 | -0.004205 |
| x | 0.002529 | 0.040190 | -0.032507 |
| z | -0.004205 | -0.032507 | 0.032607 |
se (res)
nobs (res)
r2 (res)