Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feols: speed up the creation of interacted fixed effects via fe1^fe2 syntax #475

Merged
merged 1 commit into from
Jun 5, 2024
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
13 changes: 8 additions & 5 deletions pyfixest/estimation/model_matrix_fixest_.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,14 @@ def _fixef_interactions(fval: str, data: pd.DataFrame) -> tuple[str, pd.DataFram
for val in fval.split("+"):
if "^" in val:
vars = val.split("^")
data[val.replace("^", "_")] = data[vars].apply(
lambda x: (
"^".join(x.dropna().astype(str)) if x.notna().all() else np.nan
),
axis=1,
data[val.replace("^", "_")] = (
data[vars[0]]
.astype(pd.StringDtype())
.str.cat(
data[vars[1:]].astype(pd.StringDtype()),
sep="^",
na_rep=None, # a row containing a missing value in any of the columns (before concatenation) will have a missing value in the result: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.cat.html
)
)

return fval.replace("^", "_"), data
Expand Down
Loading