Examples¶
Each page here follows one of the scripts in
examples/ of
the repository, explains what it shows, and ends with the script itself. They
all run on simulated data, so there is nothing to download and nothing to
configure. Clone the repository, install the package and run any of them:
pip install -e ".[formula]" # pyfixest is needed for formula syntax
python examples/quickstart.py
The first run writes a simulated panel of 20,000 workers (about 170,000 rows)
to examples/output/; later runs reuse it. Delete that directory to start
fresh. It also holds each example’s scratch space and result files, and nothing
in it is needed afterwards. Run them from anywhere: paths are resolved relative
to the example file, not your working directory. The outputs shown on these
pages are from those runs, abridged.
fit a three-way fixed-effects model on a Parquet file and read the results. Start here. |
|
the application the library was written for, aggregated in a streaming pass |
|
formula syntax end to end, missing values and |
|
analytic and frequency weights, and 2SLS with a first-stage F |
|
a within regression, OLS with an intercept, and |
|
|
|
hundreds of covariates, and sizing the batches to them |
|
worker-specific trends, the streamed dimension, and the low-level interface |
|
memory, disk, solvers and logging: read this before pointing the library at something large |
|
regression tables and plots via pyfixest |
|
connected components, |
|
the KSS bias correction, checked against the effects the data was built from |
The simulated data¶
hdfe_stream.simulate ships with the package, so you can try the library, or
check your own code, against data whose answer you know:
from hdfe_stream.simulate import simulate_akm
simulate_akm(n_workers=1_000_000).write_parquet("sim.parquet")
simulate_akmis the base matched worker–firm panel. Workers move between firms, and log earnings are a worker effect plus a firm effect plus an age profile plus noise. Effects are positively assorted, so the fixed effects genuinely have to be estimated jointly, and there is enough mobility to link the firms into one connected component.simulate_richadds categoricals, cluster variables that are not fixed effects, weights, an instrumental-variables block, a second outcome, and a column with missing values.simulate_trendsadds worker-specific time trends, for varying slopes.simulate_bottleneckbuilds a panel whose variance components are weakly identified: two blocks of firms joined by a handful of movers.
All of them take a seed and are deterministic. Because the worker and firm
effects are drawn explicitly, you know the right answer, which is what makes
these useful for checking your own code as well as the library’s.
examples/simulated_data.py
is the helper the examples import for their data paths and scratch
directories. It is not an example itself, but it is short and worth a look if
you want to know what the simulated columns mean.