analyze_regression_table
source
analyze_regression_table(
df,
dvs= None ,
idvs= None ,
feffects= None ,
clusters= None ,
* ,
byvar= None ,
format = 'gt' ,
)
Build a regression table of one or more OLS models.
Supports fixed effects and clustered standard errors (via pyfixest), multiple models side by side, or a single model estimated separately across the levels of byvar.
Parameters
df
pd .DataFrame
Data frame containing the data.
required
dvs
Sequence [str ] | str | None
Dependent variable name, or a list of names (one per model). Defaults to the declared main outcome (:func:expdpy.set_roles) when omitted.
None
idvs
Sequence [str ] | Sequence [Sequence [str ]] | None
Independent variable names. For multiple models, a list of lists. Defaults to the declared covariates (:func:expdpy.set_roles) when omitted.
None
feffects
Sequence [str ] | Sequence [Sequence [str ]] | None
Fixed-effects variable names (per model when multiple models are given).
None
clusters
Sequence [str ] | Sequence [Sequence [str ]] | None
Cluster variable names for clustered standard errors (per model when multiple).
None
byvar
str | None
A categorical variable to estimate the single model separately by. Only valid with a single dependent variable. Levels with too few observations to estimate the model (n <= len(idvs) + 1) are skipped.
None
format
Literal ['gt', 'tex', 'md', 'df', 'html']
Output format for the rendered etable: "gt" (Great Tables), "tex", "md", "df" (DataFrame) or "html".
'gt'
Returns
RegressionTableResult
models (fitted pyfixest models), etable (rendered table) and df (tidy coefficient frame).
Examples
Basic — a pooled OLS regression of the cubic Kuznets curve (the data dictionary supplies the readable labels shown in the rendered table):
import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def
df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel= True )
ex.analyze_regression_table(
df,
dvs= "gini_regional" ,
idvs= ["log_gdp_pc" , "log_gdp_pc_sq" , "log_gdp_pc_cu" ],
).etable
(1)
coef
Log GDP per capita
6.385***
(0.134)
Log GDP per capita²
-0.711***
(0.015)
Log GDP per capita³
0.026***
(0.001)
Intercept
-18.490***
(0.402)
stats
Observations
880
R2
0.744
Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001. Format of coefficient cell: Coefficient (Std. Error)
Advanced — absorb two-way (country + year) fixed effects with standard errors clustered by country, then read the tidy coefficient frame and fitted models:
import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def
df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel= True )
result = ex.analyze_regression_table(
df,
dvs= "gini_regional" ,
idvs= ["log_gdp_pc" , "log_gdp_pc_sq" , "log_gdp_pc_cu" ],
feffects= ["country" , "year" ],
clusters= ["country" ],
)
result.etable
result.df
result.models
[<pyfixest.estimation.models.feols_.Feols at 0x7f49647a3c20>]