set_roles
source
set_roles(df, * , outcome= None , covariates= None )
Declare the main outcome and covariates on df and return it.
The roles are stored under df.attrs["expdpy_roles"] so that subsequent explore_* / analyze_* calls (and the no-code apps) can default to them when their primary variable argument is omitted. Explicit arguments to those functions still take precedence.
Parameters
df
pd .DataFrame
The data frame (modified in place — its attrs are updated and the same object is returned).
required
outcome
str | None
Name of the main outcome (dependent) variable, or None to leave it unset.
None
covariates
str | Sequence [str ] | None
Name(s) of the main covariate(s) — a single column or a sequence — or None to leave them unset.
None
Examples
Declare the key variables once, then explore/analyze without repeating them:
import expdpy as ex
from expdpy.data import load_kuznets
df = ex.set_panel(load_kuznets(), entity= "country" , time= "year" )
df = ex.set_roles(df, outcome= "gini_regional" , covariates= ["log_gdp_pc" ])
ex.explore_scatter_plot(df).fig # x = log_gdp_pc, y = gini_regional
ex.analyze_regression_table(df).etable # gini_regional ~ log_gdp_pc
(1)
coef
log_gdp_pc
-0.005**
(0.002)
Intercept
0.323***
(0.019)
stats
Observations
880
R2
0.008
Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001. Format of coefficient cell: Coefficient (Std. Error)