Utilities

dpd_stream.etable(models, **kwargs)[source]

pf.etable for streaming results: a regression table of HDFEResult and HDFEMulti models, 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.etable itself matches rows on the literal text). With type="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.etable returns for the type asked 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 = 0 across models.

Each p-value, from HDFEResult.tidy, is multiplied by the number of hypotheses (models times parameters), capped at 1. As pyfixest’s bonferroni, which takes one parameter.

Parameters:
  • models (HDFEResult, HDFEMulti, or a list of them) – The models.

  • param (str or list of str) – The coefficient(s) tested in every model; each must be in every model.

Returns:

polars.DataFrame – One row per model and parameter: model (its position), fml, the tidy columns, and Bonferroni Pr(>|t|).

dpd_stream.holm(models, param)[source]

Holm’s step-down adjusted p-values for param = 0 across 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:
Returns:

polars.DataFrame – As in bonferroni, with Holm 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() and fixef() stop working). Skipped unless force=True: runs of other processes still alive on this host, runs from other hosts (their liveness can’t be checked), and runs younger than older_than_hours if given.

Parameters:
  • workdir (str or Path, optional) – The directory to sweep. Default: the HDFE_STREAM_WORKDIR environment 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, with dry_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 cluster grouping the panels into this many clusters.

  • weights (bool) – Add a column wt of 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 (and cluster, 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 formula y ~ l(y, 1:p) + x + w names them.