Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/maketables/etable.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class ETable(MTable):
Any coefficients not in the list will appear at the end in their original order.
This is applied after keep/drop filtering.
Example: order=['age', 'female', 'education'] will place these first.
feorder : list[str], optional
Explicit order for fixed effects rows. Provide a list of fixed effect names
to specify their display order. Any fixed effects not in the list will appear
at the end sorted alphabetically.
Example: feorder=['f1', 'f2'] will place these first.
labels : dict, optional
Variable labels for relabeling dependent vars, regressors, and (if not
provided in felabels) fixed effects. If None, labels are collected from
Expand Down Expand Up @@ -178,6 +183,7 @@ def __init__(
drop: list | str | None = None,
exact_match: bool | None = False,
order: list[str] | None = None,
feorder: list[str] | None = None,
labels: dict | None = None,
cat_template: str | None = None,
show_fe: bool | None = None,
Expand Down Expand Up @@ -249,7 +255,7 @@ def __init__(
# relabel dependent variables
if labels:
dep_var_list = [labels.get(d, d) for d in dep_var_list]
fixef_list = self._collect_fixef_list(models, show_fe)
fixef_list = self._collect_fixef_list(models, show_fe, feorder=feorder)

# --- bottom model stats keys (modular default) ---
if model_stats is None:
Expand Down Expand Up @@ -459,7 +465,7 @@ def _collect_labels_from_models(self, models: list[Any]) -> dict[str, str]:
pass
return merged

def _collect_fixef_list(self, models: list[Any], show_fe: bool) -> list[str]:
def _collect_fixef_list(self, models: list[Any], show_fe: bool, feorder: list[str] | None = None) -> list[str]:
if not show_fe:
return []
fixef_list: list[str] = []
Expand All @@ -468,7 +474,14 @@ def _collect_fixef_list(self, models: list[Any], show_fe: bool) -> list[str]:
if fx and fx != "0":
fixef_list += fx.split("+")
fixef_list = [x for x in fixef_list if x]
return sorted(set(fixef_list))

# Apply optional ordering if provided via feorder parameter
if feorder is not None:
ordered_res = [name for name in feorder if name in fixef_list]
remaining = sorted(set(fixef_list) - set(feorder))
return ordered_res + remaining
else:
return sorted(set(fixef_list))

def _compute_stars(self, p: pd.Series, signif_code: list[float]) -> pd.Series:
if not signif_code:
Expand Down
Loading