Skip to content

Commit

Permalink
Merge pull request #660 from leostimpfle/iterative-rectifier-2
Browse files Browse the repository at this point in the history
Reopen iterative rectifier PR
  • Loading branch information
leostimpfle authored Oct 22, 2024
2 parents 09a6a5e + f10c3be commit 8435537
Show file tree
Hide file tree
Showing 24 changed files with 1,391 additions and 19 deletions.
10 changes: 10 additions & 0 deletions pyfixest/estimation/FixestMulti_.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(
seed: Optional[int],
split: Optional[str],
fsplit: Optional[str],
separation_check: Optional[list[str]] = None,
) -> None:
"""
Initialize a class for multiple fixed effect estimations.
Expand Down Expand Up @@ -57,6 +58,9 @@ def __init__(
seed : Optional[int]
Option to provide a random seed. Default is None.
Only relevant for wild cluster bootstrap for use_compression=True.
separation_check: list[str], optional
Only used in "fepois". Methods to identify and drop separated observations.
Either "fe" or "ir". Executes both by default.
Returns
-------
Expand All @@ -70,6 +74,7 @@ def __init__(
self._use_compression = use_compression
self._reps = reps if use_compression else None
self._seed = seed if use_compression else None
self._separation_check = separation_check

self._run_split = split is not None or fsplit is not None
self._run_full = not (split and not fsplit)
Expand Down Expand Up @@ -186,6 +191,7 @@ def _estimate_all_models(
collin_tol: float = 1e-6,
iwls_maxiter: int = 25,
iwls_tol: float = 1e-08,
separation_check: Optional[list[str]] = None,
) -> None:
"""
Estimate multiple regression models.
Expand All @@ -208,6 +214,9 @@ def _estimate_all_models(
iwls_tol : float, optional
The tolerance level for the IWLS algorithm. Default is 1e-8.
Only relevant for non-linear estimation strategies.
separation_check: list[str], optional
Only used in "fepois". Methods to identify and drop separated observations.
Either "fe" or "ir". Executes both by default.
Returns
-------
Expand Down Expand Up @@ -318,6 +327,7 @@ def _estimate_all_models(
lean=_lean,
sample_split_value=sample_split_value,
sample_split_var=_splitvar,
separation_check=separation_check,
# solver=_solver
)
FIT.prepare_model_matrix()
Expand Down
19 changes: 19 additions & 0 deletions pyfixest/estimation/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def fepois(
iwls_tol: float = 1e-08,
iwls_maxiter: int = 25,
collin_tol: float = 1e-10,
separation_check: Optional[list[str]] = ["fe"],
solver: str = "np.linalg.solve",
drop_intercept: bool = False,
i_ref1=None,
Expand Down Expand Up @@ -471,6 +472,10 @@ def fepois(
collin_tol : float, optional
Tolerance for collinearity check, by default 1e-10.
separation_check: list[str], optional
Methods to identify and drop separated observations.
Either "fe" or "ir". Executes "fe" by default.
solver : str, optional.
The solver to use for the regression. Can be either "np.linalg.solve" or
"np.linalg.lstsq". Defaults to "np.linalg.solve".
Expand Down Expand Up @@ -569,6 +574,7 @@ def fepois(
seed=None,
split=split,
fsplit=fsplit,
separation_check=separation_check,
)

fixest = FixestMulti(
Expand Down Expand Up @@ -598,6 +604,7 @@ def fepois(
iwls_tol=iwls_tol,
iwls_maxiter=iwls_maxiter,
collin_tol=collin_tol,
separation_check=separation_check,
solver=solver,
)

Expand Down Expand Up @@ -625,6 +632,7 @@ def _estimation_input_checks(
seed: Optional[int],
split: Optional[str],
fsplit: Optional[str],
separation_check: Optional[list[str]] = None,
):
if not isinstance(fml, str):
raise TypeError("fml must be a string")
Expand Down Expand Up @@ -726,3 +734,14 @@ def _estimation_input_checks(

if isinstance(fsplit, str) and fsplit not in data.columns:
raise KeyError(f"Column '{fsplit}' not found in data.")

if separation_check is not None:
if not isinstance(separation_check, list):
raise TypeError(
"The function argument `separation_check` must be of type list."
)

if not all(x in ["fe", "ir"] for x in separation_check):
raise ValueError(
"The function argument `separation_check` must be a list of strings containing 'fe' and/or 'ir'."
)
Loading

0 comments on commit 8435537

Please sign in to comment.