Estimation

dpd_stream.dpd_stream(fml, data, panel, *, system=False, steps=2, transform='fd', vcov='robust', gmm=None, iv=None, collapse=False, h=None, small=False, artests=2, constant=True, pca=False, components=0, weights=None, weights_type='aweights', tdelta=None, nl=None, nl_weight=1.0, workdir=None, **options)[source]

Arellano-Bond (difference) or Blundell-Bond (system) GMM for dynamic panels, out of core. Option names and conventions follow Stata’s xtabond2 where they overlap.

Parameters:
  • fml (str) – "y ~ regressors | time effects | instruments", the last two optional. Lags use fixest’s operators: l(x, 1), l(y, 1:2), f(x, 1), d(x). The instrument part is gmm() and iv() terms joined by +: gmm(vars, a:b, collapse=True, eq='diff', passthru=True, orthogonal=True, split=True) (lags a to b of the variables, . for no upper limit; default 1:., as xtabond2) and iv(vars, eq='level', passthru=True, mz=True). Several variables in one term are joined by +: gmm(n + w, 2:.). Time effects (| year) are absorbed: estimated as a dummy per period, each also an IV-style instrument (xtabond2’s yr* in the regressors and in iv()), and not reported. In difference GMM, | g^year (g constant within panels: region, industry) absorbs a period effect for each value of g, partialled out of the moments, with the same estimates as its dummies would give.

  • data (str, Path, polars LazyFrame or DataFrame) – A Parquet file (or glob), or a Polars frame. It is read once.

  • panel ((str, str)) – The panel identifier and the time variable (integer periods).

  • system (bool, default False) – System GMM (Blundell and Bond 1998): the levels equation is added, with a constant. False is difference GMM (xtabond2’s noleveleq).

  • steps ({1, 2, "iterated"}, default 2) – One-step, two-step, or iterated GMM (the weight matrix updated until the estimates converge, as xtdpdgmm’s igmm).

  • transform ({"fd", "fod"}, default "fd") – First differences, or forward orthogonal deviations (xtabond2’s orthogonal), which keep more observations in unbalanced panels.

  • vcov (default "robust") – "robust": clustered by panel, and for two-step with Windmeijer’s (2005) correction. "iid": the non-robust one-step variance (for two-step, the uncorrected one). {"CRV1": "var"} or {"CRV1": "var1+var2"}: clustered by any variables, multi-way by inclusion and exclusion; as in xtabond2’s cluster(), the clustering also defines the two-step weight matrix.

  • gmm (list of Gmm, list of Iv, optional) – Instruments as objects, added after the formula’s.

  • iv (list of Gmm, list of Iv, optional) – Instruments as objects, added after the formula’s.

  • collapse (bool, default False) – Collapse every GMM-style group.

  • h ({1, 2, 3}, optional) – xtabond2’s h(): the one-step weight matrix’s prior error covariance (default 3).

  • small (bool, default False) – t and F statistics with small-sample corrections, as xtabond2’s small.

  • artests (int, default 2) – Arellano-Bond tests up to this order.

  • constant (bool, default True) – System GMM’s constant (False: xtabond2’s noconstant).

  • pca (bool, default False) – Replace the GMM-style instruments by their principal components (xtabond2’s pca); components fixes how many.

  • weights (str, optional) – A column of weights; weights_type "aweights" (default) or "pweights" (robust variance).

  • tdelta (int, optional) – The time variable’s step (default 1).

  • nl ({None, "noserial", "iid"}) – Add Ahn and Schmidt’s (1995) nonlinear moment conditions, as xtdpdgmm’s nl(). "noserial", valid when the idiosyncratic errors are serially uncorrelated: E[u_iT (u_it - u_i,t-1)] = 0 for t < T, u the errors in levels (with the panel effect). "iid", when they are also homoskedastic over time: E[ubar_i (u_it - u_i,t-1)] = 0 for every period, and the linear E[y_i,t-2 du_i,t-1 - y_i,t-1 du_it] = 0. One per period, or one of each with collapse. Estimated by Gauss-Newton, with Windmeijer’s correction in its general form; a one-step fit has the sandwich variance.

  • nl_weight (float, default 1) – The first step’s weight on the nonlinear moments relative to the linear ones (xtdpdgmm’s nl(, weight())): its weight matrix is the linear moments’ (Z’HZ)^- and, for each nonlinear moment, 1 / (the number of panels) times this. 0 ignores them in the first step, which is then the linear one-step estimate.

  • workdir (str or Path, optional) – Where the run directory goes (default $DPD_STREAM_WORKDIR, then $HDFE_STREAM_WORKDIR, then the system temporary directory).

  • **options – storage ("disk" or "memory"), block_mb (rows per block, by size), tol and maxiter (iterated GMM), n_threads, diffsargan (False skips the difference-in-Hansen tests), idtests ("auto": the identification tests when the excluded instruments times the endogenous regressors are at most 500; True, False), verbose, logger, log_level.

Returns:

DPDResult

Examples

>>> from dpd_stream import dpd_stream
>>> from dpd_stream.simulate import simulate_dynamic
>>> df = simulate_dynamic(2_000, 8, seed=1)
>>> fit = dpd_stream("y ~ l(y, 1) + x + w | year | gmm(y, 2:4) + gmm(x, 1:3) + iv(w)",
...                  df, panel=("id", "year"), system=True, verbose=False)
>>> fit.summary()
class dpd_stream.Gmm[source]

A group of GMM-style instruments, as xtabond2’s gmm() option.

Parameters:
  • vars (str or list of str) – The variables (terms) the instruments are made from: column names, expressions, or lag terms such as "l(n, 1)"; a string may join several with +. One group of several variables gives one set of instruments, interleaved, as gmm(L.(n w k)) does.

  • lags ((int, int or None), default (1, None)) – The lag limits a and b: lags a to b of the variables instrument the transformed equation (None for “as many as the data allow”, xtabond2’s .). For system GMM, the levels equation gets lag a - 1 of their differences.

  • collapse (bool, default False) – One instrument per lag and variable instead of one per lag, variable and period.

  • eq ({"both", "diff", "level"}, default "both") – Which equation the instruments are for. "level" gives differenced instruments for the levels equation (system GMM).

  • passthru (bool, default False) – Levels-equation instruments are not differenced.

  • orthogonal (bool, default False) – Backward orthogonal deviations of the variables as instruments for the transformed equation (to pair with transform="fod").

  • split (bool, default False) – In system GMM, test the levels-equation instruments separately in the difference-in-Hansen tests (xtabond2’s split).

__init__(vars, lags=(1, None), collapse=False, eq='both', passthru=False, orthogonal=False, split=False)
classmethod __new__(*args, **kwargs)
class dpd_stream.Iv[source]

A group of IV-style instruments (one column per variable), as xtabond2’s iv() option.

Parameters:
  • vars (str or list of str) – The variables: names, expressions, lag terms, i(year).

  • eq ({"both", "diff", "level"}, default "both") – The equation(s) the instruments are for.

  • passthru (bool, default False) – Use the variables as they are in the transformed equation instead of transforming them.

  • mz (bool, default False) – Missing values become 0 instead of dropping the observation.

__init__(vars, eq='both', passthru=False, mz=False)
classmethod __new__(*args, **kwargs)