Utilities¶
- dpd_stream.etable(models, **kwargs)[source]¶
pf.etablefor streaming results: a regression table ofHDFEResultandHDFEMultimodels, mixed freely with ordinary pyfixest models.A multi-model result expands into one column per model. The spacing of the fixed-effect side is normalized, so
"a + b"and"a+b"share a row (pf.etableitself matches rows on the literal text). Withtype="tex", labels are escaped for LaTeX.- Parameters:
models (HDFEResult, HDFEMulti, or a list of them and pyfixest models) – The models, one column each.
**kwargs – Passed to
pf.etable:type,model_stats,labels,felabels,file_name, …
- Returns:
object – What
pf.etablereturns for thetypeasked for.
Examples
>>> etable([fit1, fit2], type="df", model_stats=["N", "se_type", "r2"])
- dpd_stream.bonferroni(models, param)[source]¶
Bonferroni-adjusted p-values for
param = 0across models.Each p-value, from
HDFEResult.tidy, is multiplied by the number of hypotheses (models times parameters), capped at 1. As pyfixest’sbonferroni, which takes one parameter.- Parameters:
- Returns:
polars.DataFrame – One row per model and parameter:
model(its position),fml, thetidycolumns, andBonferroni Pr(>|t|).
- dpd_stream.holm(models, param)[source]¶
Holm’s step-down adjusted p-values for
param = 0across models.The p-values are sorted from smallest to largest, the j-th of m is multiplied by m - j + 1, and each adjusted p-value is the running maximum of those, capped at 1. Like Bonferroni’s, the adjustment controls the familywise error rate under any dependence between the tests, and no adjusted p-value is larger than Bonferroni’s, so it rejects at least as often (Holm, 1979).
- Parameters:
models – As in
bonferroni.param – As in
bonferroni.
- Returns:
polars.DataFrame – As in
bonferroni, withHolm Pr(>|t|).
- dpd_stream.cleanup(workdir=None, older_than_hours=None, force=False, dry_run=False)[source]¶
Remove leftover run directories, e.g. from killed processes.
Only directories created by hdfe_stream (they carry a marker file) are touched, and empty ones named like them (whose files were deleted but which could not be removed while a file in them was still open, as on NFS); every new fit removes those too.
Runs of this process are removed unless a fit is still running in them (this includes result files of finished fits; their
resid()andfixef()stop working). Skipped unlessforce=True: runs of other processes still alive on this host, runs from other hosts (their liveness can’t be checked), and runs younger thanolder_than_hoursif given.- Parameters:
workdir (str or Path, optional) – The directory to sweep. Default: the
HDFE_STREAM_WORKDIRenvironment variable if set, else the system temporary directory.older_than_hours (float, optional) – Skip runs younger than this.
force (bool, default False) – Remove runs of live processes and of other hosts too.
dry_run (bool, default False) – List what would be removed, and remove nothing.
- Returns:
list of (str, int) –
(path, bytes)for each run that was (or, withdry_run, would be) removed.
- dpd_stream.simulate.simulate_dynamic(n_panels=1000, T=8, *, rho=(0.5,), beta=1.0, gamma=0.5, x_type='predetermined', delta=0.5, theta=0.5, phi=0.3, sd_alpha=1.0, sd_eps=1.0, time_effects=True, stationary=True, burn=50, unbalanced=False, p_gap=0.0, n_clusters=None, weights=False, heteroskedastic=False, start_year=2000, seed=0)[source]¶
A simulated dynamic panel.
- Parameters:
n_panels (int) – Panels and periods (before any are dropped).
T (int) – Panels and periods (before any are dropped).
rho (sequence of float) – The coefficients on the lags of y (stationary: their sum below 1).
beta (float) – The coefficients on x and on w.
gamma (float) – The coefficients on x and on w.
x_type ({"predetermined", "endogenous", "exogenous"}) – x_it = delta x_i,t-1 + theta alpha_i + phi eps_i,t-1 (predetermined) or phi eps_it (endogenous) or nothing (exogenous), + noise.
sd_alpha (float) – Standard deviations of the fixed effects and the shocks.
sd_eps (float) – Standard deviations of the fixed effects and the shocks.
time_effects (bool) – Add common time effects lambda_t (then fit with time effects).
stationary (bool) – Start each panel at its long-run mean (see the module docstring).
burn (int) – Periods simulated and discarded before the first one kept.
unbalanced (bool) – Panels start and end at random periods (each keeps at least 3).
p_gap (float) – Probability that an observation inside a panel is missing (a gap).
n_clusters (int, optional) – Add a column
clustergrouping the panels into this many clusters.weights (bool) – Add a column
wtof panel-level weights (uniform on 0.5..2).heteroskedastic (bool) – Shocks’ standard deviation varies by panel (uniform on 0.5..1.5 times
sd_eps).start_year (int) – The first period’s
year.seed (int)
- Returns:
polars.DataFrame – Columns
id,year,y,x,w(andcluster,wt), sorted by id and year.
- dpd_stream.simulate.truth_dynamic(rho=(0.5,), beta=1.0, gamma=0.5)[source]¶
The true coefficients of
simulate_dynamic, named as a formulay ~ l(y, 1:p) + x + wnames them.