Skip to content

Commit

Permalink
pyfixest 0.9.11 (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
s3alfisc authored Sep 27, 2023
1 parent 466a286 commit a841eab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
5 changes: 5 additions & 0 deletions docs/news.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# News

## PyFixest `0.9.11`

- Bump required `formulaic` version to `0.6.5`.
- Stop copying the data frame in `fixef()`.

## PyFixest `0.9.10`

- Fixes a big in the `wildboottest` method (see [#158](https://github.com/s3alfisc/pyfixest/issues/158)).
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions pyfixest/feols.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def fixef(self) -> None:
This method creates the following attributes:
- `alphaDF` (pd.DataFrame): A DataFrame with the estimated fixed effects.
- `sumDF` (np.array): An array with the sum of fixed effects for each observation (i = 1, ..., N).
- `sumFE` (np.array): An array with the sum of fixed effects for each observation (i = 1, ..., N).
Args:
None
Expand Down Expand Up @@ -747,19 +747,18 @@ def fixef(self) -> None:
depvars, res = _fml.split("~")
covars, fixef_vars = res.split("|")

df = _data.copy()
# all fixef vars to pd.Categorical
for x in fixef_vars.split("+"):
df[x] = pd.Categorical(df[x])
fixef_vars = fixef_vars.split("+")
fixef_vars_C = [f"C({x})" for x in fixef_vars]
fixef_fml = "+".join(fixef_vars_C)

fml_linear = f"{depvars} ~ {covars}"
Y, X = model_matrix(fml_linear, df)
Y, X = model_matrix(fml_linear, _data)
X = X[self._coefnames] # drop intercept, potentially multicollinear vars
Y = Y.to_numpy().flatten().astype(np.float64)
X = X.to_numpy()
uhat = csr_matrix(Y - X @ self._beta_hat).transpose()

D2 = model_matrix("-1+" + fixef_vars, df, output="sparse")
D2 = model_matrix("-1+" + fixef_fml, _data, output="sparse")
cols = D2.model_spec.column_names

alpha = spsolve(D2.transpose() @ D2, D2.transpose() @ uhat)
Expand Down Expand Up @@ -829,7 +828,6 @@ def predict(self, newdata: Optional[pd.DataFrame] = None) -> np.ndarray:
self.fixef()

fvals = self._fixef.split("+")

df_fe = newdata[fvals].astype(str)

# populate matrix with fixed effects estimates
Expand All @@ -839,7 +837,9 @@ def predict(self, newdata: Optional[pd.DataFrame] = None) -> np.ndarray:
for i, fixef in enumerate(df_fe.columns):
new_levels = df_fe[fixef].unique()
old_levels = _data[fixef].unique().astype(str)
subdict = self._fixef_dict[fixef]
subdict = self._fixef_dict[
f"C({fixef})"
] # as variables are called C(var) in the fixef_dict

for level in new_levels:
# if level estimated: either estimated value (or 0 for reference level)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[tool.poetry]
name = "pyfixest"
version = "0.9.10"
version = "0.9.11"


description = "Experimental draft package for high dimensional fixed effect estimation. Supports OLS and IV estimation."
description = "(Not so) experimental draft package for high dimensional fixed effect estimation. Supports OLS, IV and Poisson regression and a range of inference procedures."
authors = ["Alexander Fischer <alexander-fischer1801@t-online.de>"]
license = "MIT"
readme = "readme.md"
Expand All @@ -16,7 +16,7 @@ pandas=">=1.1.0"
numpy=">=1.19.0"
PyHDFE=">=0.2"
scipy=">=1.6"
formulaic=">=0.6.0"
formulaic=">=0.6.5"
pytest="^7.0.0"
lets-plot = "^4.0.1"
wildboottest={ version = ">=0.2", optional = true}
Expand Down

0 comments on commit a841eab

Please sign in to comment.