regtools.linmodels package

Submodules

regtools.linmodels.reg module

regtools.linmodels.reg.linear_reg(df, yvar, xvars, entity_var, time_var, robust=True, cluster=False, cons=True, fe=None, interaction_tuples=None, num_lags=0, lag_variables='xvars', lag_period_var='Date', lag_id_var='TICKER', lag_fill_method='ffill', lag_fill_limit=None, reg_type='fama macbeth', **fit_kwargs)[source]

Runs a regression from the linearmodels library, standardizing the output to that of statsmodels

Parameters
  • df (DataFrame) –

  • yvar (str) – column name of outcome y variable

  • xvars (Sequence[str]) – column names of x variables for regression

  • entity_var (str) – column name of variable representing entities in the data

  • time_var (str) – column name of variable representing time in the data

  • robust (bool) – set to True to use heterskedasticity-robust standard errors

  • cluster (Union[bool, str, Sequence[str]]) – set to a column name to calculate standard errors within clusters given by unique values of given column name. set to multiple column names for multiway clustering following Cameron, Gelbach, and Miller (2011). NOTE: will get exponentially slower as more cluster variables are added

  • cons (bool) – set to False to not include a constant in the regression

  • fe (Union[str, Sequence[str], None]) – If a str or list of strs is passed, uses these categorical variables to construct dummies for fixed effects.

  • interaction_tuples (Union[Tuple[str, str], Sequence[Tuple[str, str]], None]) – tuple or list of tuples of column names to interact and include as xvars

  • num_lags (int) – Number of periods to lag variables. Setting to other than 0 will activate lags

  • lag_variables (Union[str, Sequence[str]]) – ‘all’, ‘xvars’, or list of strs of names of columns to lag for regressions.

  • lag_period_var (str) – only used if lag_variables is not None. name of column which contains period variable for lagging

  • lag_id_var (str) – only used if lag_variables is not None. name of column which contains identifier variable for lagging

  • lag_fill_method (Optional[str]) – ‘ffill’ or ‘bfill’ for which method to use to fill in missing rows when creating lag variables. Set to None to not fill and have missing instead. See pandas.DataFrame.fillna for more details

  • lag_fill_limit (Optional[int]) – maximum number of periods to fill with lag_fill_method

  • reg_type (str) – ‘fmb’ for type of model

  • fit_kwargs

Returns

statsmodels regression result.