Skip to content

Global Options #930

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
38 changes: 38 additions & 0 deletions docs/quickstart.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,41 @@ pf.etable([fit_twfe, fit_did2s])
```

For more details see the vignette on [Difference-in-Differences Estimation](https://py-econometrics.github.io/pyfixest/difference-in-differences.html).

## Setting Global Options

We can set all function arguments of the estimation functions `feols`, `fepois`, and `feglm` as global options.

For example, we can set the estimation data set, variance covariance matrix, weights, small sample corrections and demeaner backend defaults via `pf.set_options()`.

```{python}
pf.set_options(
data = pf.get_data().dropna(),
vcov = {"CRV1": "f1"},
weights = "weights",
demeaner_backend = "rust"
)
```

In this case, we don't have to provide data, vcov, weights, etc to the model call: they will automatically be applied.

```{python}
fit1 = pf.feols(fml = "Y~X1")
```

If we actively set a function argument, the global default will be overwritten:

```{python}
fit2 = pf.feols(fml = "Y ~ X1", vcov = "hetero")

pf.etable([fit1, fit2])
```

We can set a local option context in the following way:

```{python}
with option_context(vcov="hetero"):
fit3 = pf.feols("Y ~ X1")

pf.etable([fit1, fit2, fit3])
```
3 changes: 3 additions & 0 deletions pyfixest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
rwolf,
wyoung,
)
from pyfixest.options import option_context, set_option
from pyfixest.report import coefplot, dtable, etable, iplot, make_table, summary
from pyfixest.utils import (
get_data,
Expand All @@ -49,9 +50,11 @@
"iplot",
"lpdid",
"make_table",
"option_context",
"panelview",
"report",
"rwolf",
"set_option",
"ssc",
"summary",
"utils",
Expand Down
Loading
Loading