API Reference

Model Types

DynamicPanelModels.DifferenceGMMType
DifferenceGMM(; robust=false, steps=1, windmeijer=true)

Hyperparameters for the Difference GMM estimator of dynamic panel data models (Arellano & Bond, 1991).

First-differencing eliminates the individual fixed effect η_i from y_it = α y_{i,t-1} + x_it'β + η_i + ε_it, giving Δy_it = α Δy_{i,t-1} + Δx_it'β + Δε_it. Lagged levels y_{i,t-2}, y_{i,t-3}, … are valid instruments for Δy_{i,t-1} under the assumption that ε_it is not serially correlated (so E[Δε_it · y_{i,t-s}] = 0 for s ≥ 2); this is what ar_test checks (a significant AR(2) statistic on the differenced residuals signals misspecification). One-step uses the Arellano-Bond (1991, p.279) weighting matrix A_N = N⁻¹ Σᵢ Zᵢ'HZᵢ (H reflecting the MA(1) structure that differencing induces in homoskedastic errors); two-step re-weights by the estimated one-step residual covariance and, when windmeijer=true, applies the Windmeijer (2005) finite-sample correction to avoid understating the two-step standard errors.

Arguments

  • robust::Bool=false: Compute robust standard errors if true.
  • steps::Int=1: Number of GMM steps (1 = one-step, 2 = two-step). Must be ≥ 1.
  • windmeijer::Bool=true: Apply Windmeijer finite-sample correction when robust=true.
source
DynamicPanelModels.SystemGMMType
SystemGMM(; robust=false, steps=1, windmeijer=true)

Create a SystemGMM object representing hyperparameters for the System GMM estimator of dynamic panel data models (Blundell & Bond, 1998).

Stacks the Difference GMM equations with an additional levels equation y_it = α y_{i,t-1} + x_it'β + η_i + ε_it, instrumented with lagged differences Δy_{i,t-1}, Δx_{i,t-1} rather than lagged levels. This is valid under the mean-stationarity assumption E[η_i Δy_{i,t}] = 0 (deviations of the initial condition from its long-run mean are uncorrelated with that mean) — see Blundell & Bond (1998, Sec. 2.3.1). System GMM is most useful when the autoregressive parameter is close to unity, where lagged levels become weak instruments for Δy_{i,t-1} in plain Difference GMM. Because the extra identifying assumption is not implied by the model and is not automatically tested, inspect sargan_test/diff_hansen_test before trusting System GMM estimates on highly persistent series.

Arguments

  • robust::Bool=false: Compute robust standard errors if true.
  • steps::Int=1: Number of GMM steps (1 = one-step, 2 = two-step). Must be ≥ 1.
  • windmeijer::Bool=true: Apply Windmeijer finite-sample correction for robust standard errors.
source
DynamicPanelModels.AndersonHsiaoType
AndersonHsiao()

Anderson–Hsiao (1981) instrumental-variables estimator for dynamic panel data models.

Estimates the first-differenced equation Δy_it = α Δy_{i,t-1} + Δx_it'β + Δε_it by IV, instrumenting Δy_{i,t-1} with a single lagged level y_{i,t-2} (or, equivalently, Δy_{i,t-2}). Unlike Difference/System GMM it uses exactly one instrument for the lagged-difference regressor rather than the full set of valid lags, so it is consistent but generally less efficient; it has no tuning hyperparameters and serves as a simple baseline for comparison.

source
DynamicPanelModels.DynamicPanelResultType
DynamicPanelResult <: RegressionModel

Result of dynamic panel data GMM estimation (e.g. Difference GMM, System GMM).

Fields

  • coef::Vector{T}: Estimated coefficients.
  • vcov::AbstractMatrix{T}: Variance–covariance matrix.
  • residuals::Vector{T}: Model residuals.
  • fitted::Vector{T}: Fitted values.
  • n_obs::Int: Number of observations.
  • n_groups::Int: Number of cross-sectional units.
  • n_instruments::Int: Number of instruments.
  • coef_names::Vector{String}: Names of coefficients.
  • X::AbstractMatrix{T}: Transformed regressor matrix.
  • y::Vector{T}: Transformed response.
  • Z::AbstractSparseMatrix{T}: Instrument matrix.
  • W::AbstractMatrix{T}: GMM weighting matrix.
  • j_stat::T: Hansen–Sargan J statistic.
  • j_pval::T: P-value of the J test.
  • windmeijer::Bool: Windmeijer correction applied (only meaningful when robust).
  • robust::Bool: Robust (cluster-sandwich) standard errors were used.
  • metadata::Dict{Symbol,Any}: Additional metadata.

Constructors

DynamicPanelResult(coef, vcov, residuals, fitted,
                   n_obs, n_groups, n_instruments, coef_names,
                   X, y, Z, W, j_stat, j_pval,
                   windmeijer, metadata; robust=windmeijer)

DynamicPanelResult(coef, vcov, residuals, fitted,
                   n_obs, n_groups, n_instruments, coef_names,
                   X, y, Z, W, j_stat, j_pval;
                   windmeijer=false, robust=windmeijer, metadata=Dict())
source
DynamicPanelModels.DynamicPanelTestType
DynamicPanelTest

Results of a diagnostic test for dynamic panel data models.

Fields

  • test_name::String: Test identifier.
  • stat::Float64: Test statistic.
  • dof::Int: Degrees of freedom.
  • pvalue::Float64: Associated p-value.
source

Estimation and Data Handling

StatsAPI.fitFunction
StatsAPI.fit(model_spec::AbstractDynamicPanelModel, data;
             formula, id_col::Symbol, time_col::Symbol, exog=String[], kwargs...)

Fit a dynamic panel model specified by model_spec using data.

The data are transformed according to formula, individual identifier id_col, and time identifier time_col, then the model is estimated via estimate.

Arguments

  • model_spec: Dynamic panel model specification.
  • data: Any Tables.jl-compatible table (e.g. a DataFrame, a named tuple of columns, CSV.File, …).

Keyword Arguments

  • formula: Model formula, either a string ("y ~ lag(y) + x") or a StatsModels @formula (@formula(y ~ lag(y) + x)). Supports lag(var[, k|a:b]) for lags and the transforms log, log10, log2, exp, sqrt, abs. See get_diff_data.
  • id_col: Column identifying individuals.
  • time_col: Column identifying time periods.
  • exog: Names of right-hand-side regressors that are strictly exogenous; these are additionally used as their own ("IV-style") GMM instruments. See get_diff_data.
  • time_effects: If true, include period dummies (exogenous). See get_diff_data.
  • transform: :fd (first differences, default) or :fod (forward orthogonal deviations, Arellano-Bover; DifferenceGMM only). See get_diff_data.
  • kwargs...: Additional keyword arguments passed to estimate — including steps, robust, collapse, max_lags, min_lag, max_lag, and drop_collinear.

Examples

fit(DifferenceGMM(robust=true), df; formula = @formula(y ~ lag(y) + x),
    id_col = :id, time_col = :time, exog = ["x"])
source
DynamicPanelModels.estimateFunction
estimate(model::AbstractDynamicPanelModel, diff_data::NamedTuple;
         steps::Int=model.steps, robust::Bool=model.robust,
         collapse::Bool=false, max_lags::Int=999)

Estimate a dynamic panel GMM model (Difference or System GMM).

By default, steps and robust are taken from the model specification (e.g. DifferenceGMM(robust=true, steps=2)); passing them explicitly as keyword arguments to estimate/fit overrides the model's settings.

Arguments

  • model::AbstractDynamicPanelModel: Either DifferenceGMM or SystemGMM.
  • diff_data::NamedTuple: Preprocessed panel data with fields:
    • y: Response vector (differenced if needed)
    • X: Design matrix
    • coef_names: Names of regressors
    • panel_info: Row metadata (id, time, is_level)
    • n_obs: Number of observations
    • id_time_to_y: Dict mapping id => Dict(time => y)
    • id_time_to_diff_y: Dict mapping id => Dict(time => Δy)
    • valid_times: Vector of observed time periods
  • Keyword arguments:
    • steps::Int: Number of GMM steps (1 or 2). Defaults to model.steps.
    • robust::Bool: Use robust (cluster-sandwich) standard errors. Defaults to model.robust.
    • windmeijer::Bool: When steps == 2 && robust, apply the Windmeijer (2005) finite-sample correction instead of the naive two-step sandwich. Defaults to model.windmeijer. Has no effect for one-step estimation.
    • collapse::Bool=false: Collapse instruments to one column per lag.
    • max_lags::Int=999: Maximum instrument lag count per period.
    • min_lag::Int=1, max_lag::Int=typemax(Int): bounds on the instrument lag order.
    • drop_collinear::Bool=true: drop linearly dependent instrument columns (as xtabond2).

Returns

  • DynamicPanelResult: Contains coefficients, standard errors, residuals, fitted values, instruments, and diagnostics.
source
DynamicPanelModels.get_diff_dataFunction
get_diff_data(data, id_col::Symbol, time_col::Symbol, formula, model::AbstractDynamicPanelModel; exog=String[])

Prepare panel data for dynamic panel GMM estimation by constructing lagged regressors, applying first differences, and optionally stacking level equations for System GMM. Observations invalid due to lagging or differencing are removed.

Arguments

  • data: Panel dataset as any Tables.jl-compatible source (e.g. a DataFrame).
  • id_col::Symbol: Column identifying individuals.
  • time_col::Symbol: Column identifying time periods.
  • formula: Model formula as a string ("y ~ lag(y) + x") or a StatsModels @formula. Supported term syntax:
    • lag(var) / lag(var, k) — first / k-th lag; lag(var, a:b) expands to one regressor per lag order in the range (e.g. lag(x, 0:1)x and L.x).
    • Whitelisted transforms log, log10, log2, exp, sqrt, abs, usable on either side and nested in a lag, e.g. log(y) ~ lag(log(y)) + log(x).
  • model::AbstractDynamicPanelModel: GMM estimator type (Difference or System GMM).
  • exog: Names of right-hand-side regressors (as they appear in coef_names, e.g. "x1" or "L.x1") that are strictly exogenous. These are appended to the instrument matrix as their own ("IV-style") instrument column, following standard practice for GMM dynamic panel estimators (Roodman, 2009); this is in addition to using them directly as regressors. The dependent variable (or its lag) may not be marked exogenous.
  • time_effects: If true, add T-2 period dummies (the first two periods are the reference, for identification in the differenced equation) as exogenous regressors.

Returns

A NamedTuple with:

  • y: Response vector.
  • X: Regressor matrix.
  • coef_names: Names of coefficients aligned with X.
  • panel_info: (id, time, is_level) metadata per observation.
  • n_obs: Number of valid observations.
  • n_groups: Number of individuals/groups.
  • id_time_to_y: Mapping of level values for instruments.
  • id_time_to_diff_y: Mapping of differenced values (System GMM).
  • valid_times: Sorted vector of panel time periods.
  • exog_idx: Column indices of X (aligned with coef_names) that are strictly exogenous.
source
DynamicPanelModels.parse_formulaFunction
parse_formula(formula::AbstractString) -> Tuple{String, Vector{String}}

Parse a simple regression formula of the form "y ~ x1 + x2 + ...". Only additive terms are supported; the sole transformation recognized is lag(var) for a lagged regressor. Interactions are not supported. A FormulaTerm from StatsModels' @formula is also accepted (see the parse_formula(::FormulaTerm) method).

Arguments

  • formula::AbstractString: Regression formula with ~ separating dependent and independent variables, and + separating regressors.

Returns

  • Tuple{String, Vector{String}}:
    • First element: dependent variable name
    • Second element: vector of independent variable names in order

Errors

Throws an error if:

  • the formula is empty or malformed,
  • ~ is missing or appears more than once,
  • no valid regressors are provided,
  • duplicate regressors are present,
  • the dependent variable appears on the right-hand side.
source
parse_formula(f::FormulaTerm) -> Tuple{String, Vector{String}}

Parse a StatsModels @formula (e.g. @formula(y ~ lag(y) + x)) into the same (dependent, regressors) form as the string parser. Intercept terms are dropped (dynamic panel GMM has no intercept in the differenced equation). Delegates to the string parse_formula for validation, so the same rules apply.

source
DynamicPanelModels.build_instrumentsFunction
build_instruments(model::AbstractDynamicPanelModel, diff_data::NamedTuple; kwargs...)

Construct the instrument matrix for a dynamic panel model.

Arguments

  • model::AbstractDynamicPanelModel: Estimator object (e.g., DifferenceGMM, SystemGMM).
  • diff_data::NamedTuple: Differenced or transformed panel data.
  • kwargs: Optional keyword arguments:
    • collapse::Bool=false: Collapse instruments to one column per lag.
    • max_lags::Int=Inf: Maximum number of lags to include as instruments.

Returns

  • AbstractMatrix: Instrument matrix specific to the model.
source
build_instruments(model::DifferenceGMM, diff_data::NamedTuple; collapse=false, max_lags=999)

Construct the Arellano-Bond (1991) instrument matrix for Difference GMM.

Arguments

  • model::DifferenceGMM: Difference GMM estimator.
  • diff_data::NamedTuple: Differenced panel data containing:
    • panel_info: Vector of observation metadata (id, time, optional is_level).
    • n_obs: Total number of observations.
    • id_time_to_y: Dict mapping (id, time) to response values.
    • valid_times: Vector of time periods.
  • collapse::Bool=false: Collapse instruments to one column per lag.
  • max_lags::Int=999: Maximum number of lags (count) per period.
  • min_lag::Int=1: Minimum instrument lag order.
  • max_lag::Int=typemax(Int): Maximum instrument lag order.

Returns

  • SparseMatrixCSC{Float64}: Sparse instrument matrix for GMM estimation.
source
build_instruments(model::SystemGMM, diff_data::NamedTuple; collapse::Bool=false, max_lags::Int=Inf)

Construct the System GMM (Blundell-Bond) instrument matrix by combining:

  1. Difference equation instruments (lags of Δy)
  2. Level equation instruments (Δy_{t-1} for t ≥ 3)

Arguments

  • model::SystemGMM: System GMM estimator object.
  • diff_data::NamedTuple: Panel data in differenced form with:
    • panel_info: Vector of observation metadata (id, time, is_level).
    • n_obs: Total number of observations.
    • id_time_to_diff_y: Dict mapping id => Dict(time => Δy) for level instruments.
    • valid_times: Vector of time periods.
  • collapse::Bool=false: Whether to collapse instruments across periods.
  • max_lags::Int=Inf: Maximum number of lags for difference instruments.

Returns

  • SparseMatrixCSC{Float64}: Combined instrument matrix for difference and level equations.
source
build_instruments(model::AndersonHsiao, diff_data::NamedTuple; kwargs...)

Construct the instrument matrix for the Anderson-Hsiao estimator.

Arguments

  • model::AndersonHsiao: Anderson-Hsiao dynamic panel model object.
  • diff_data::NamedTuple: Preprocessed panel data from get_diff_data. Any regressors named in exog (see get_diff_data) are appended as additional instrument columns.
  • kwargs...: Additional keyword arguments (currently ignored).

Returns

  • SparseMatrixCSC{Float64, Int}: Instrument matrix with one column of y_{i,t-2} for each differenced observation, plus one column per strictly exogenous regressor.
source
DynamicPanelModels.lagFunction
lag(x)

Marker for a lagged regressor inside a @formula, e.g. @formula(y ~ lag(y) + x).

Lags are resolved per cross-sectional unit during data preparation (get_diff_data), so lag is only meaningful symbolically inside a formula and is never evaluated on data directly. Calling it outside a formula raises an error.

source
DynamicPanelModels.ngroupsFunction
ngroups(model::DynamicPanelResult)

Return the number of unique cross-sectional groups in a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: Model result containing group information.

Returns

  • Int: Number of groups in the model.
source
DynamicPanelModels.ninstrumentsFunction
ninstruments(model::DynamicPanelResult)

Return the number of instruments used in a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: Model result containing instrument information.

Returns

  • Int: Number of instruments used in the estimation.
source
DynamicPanelModels.is_robustFunction
is_robust(model::DynamicPanelResult)

Check if the dynamic panel GMM estimation used robust (cluster-sandwich) standard errors, i.e. whether robust=true was in effect — this is true for one-step robust fits as well as two-step fits, regardless of whether the Windmeijer correction (see is_windmeijer) was additionally applied.

Arguments

  • model::DynamicPanelResult: The estimation result object.

Returns

  • Bool: true if robust standard errors were used, false for homoskedastic/naive SEs.
source
DynamicPanelModels.is_windmeijerFunction
is_windmeijer(model::DynamicPanelResult)

Check if the Windmeijer (2005) finite-sample correction was applied to the reported standard errors (only possible for two-step robust estimation).

Arguments

  • model::DynamicPanelResult: The estimation result object.

Returns

  • Bool: true if Windmeijer-corrected standard errors were applied, false otherwise.
source

StatsAPI Interface

StatsAPI.coefFunction
StatsAPI.coef(model::DynamicPanelResult)

Return the estimated coefficients of a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: A fitted dynamic panel GMM model.

Returns

  • Vector{Float64}: Coefficient estimates for each regressor.
source
StatsAPI.vcovFunction
StatsAPI.vcov(model::DynamicPanelResult)

Return the variance–covariance matrix of the estimated coefficients from a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: A fitted dynamic panel GMM model.

Returns

  • AbstractMatrix{T}: Variance–covariance matrix of the estimated coefficients.
source
StatsAPI.stderrorFunction
StatsAPI.stderror(model::DynamicPanelResult)

Compute the standard errors of estimated coefficients from a dynamic panel GMM model, i.e. sqrt.(diag(vcov(model))). Whether these are homoskedastic, cluster-robust, or Windmeijer-corrected depends on how the model was fit; see is_robust and is_windmeijer to check which applies to a given result.

Arguments

  • model::DynamicPanelResult: Model result containing vcov.

Returns

  • Vector{Float64}: Standard errors.
source
StatsAPI.residualsFunction
StatsAPI.residuals(model::DynamicPanelResult)

Return the residuals of a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: The fitted model containing residuals.

Returns

  • Vector{Float64}: Residuals for each observation after model transformation.
source
StatsAPI.fittedFunction
StatsAPI.fitted(model::DynamicPanelResult)

Return the fitted values from a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: A fitted dynamic panel model.

Returns

  • Vector{Float64}: Predicted values for each observation.
source
StatsAPI.predictFunction
StatsAPI.predict(model::DynamicPanelResult)

Return the predicted values from a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: A fitted dynamic panel GMM model result.

Returns

  • Vector{<:Real}: Predicted (fitted) values for each observation.
source
StatsAPI.nobsFunction
StatsAPI.nobs(model::DynamicPanelResult; count_groups=false)

Return the number of observations or groups in a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: Model result containing observations and groups.
  • count_groups::Bool=false: If true, returns number of groups; otherwise returns total observations.

Returns

  • Int: Number of observations or groups.
source
StatsAPI.dofFunction
StatsAPI.dof(model::DynamicPanelResult)

Return the degrees of freedom of a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: Estimated model object.

Returns

  • Int: Number of estimated coefficients.
source
StatsAPI.dof_residualFunction
StatsAPI.dof_residual(model::DynamicPanelResult)

Return the residual degrees of freedom of a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: Model result containing observations and estimated coefficients.

Returns

  • Int: Residual degrees of freedom (n_obs - n_coef).
source
StatsAPI.confintFunction
StatsAPI.confint(model::DynamicPanelResult; level::Real=0.95)

Compute two-sided confidence intervals for coefficients of a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: Model result containing coefficients and standard errors.
  • level::Real=0.95: Confidence level (default 0.95).

Returns

  • Matrix{Float64}: Two-column matrix with lower and upper bounds of the confidence intervals.
source
StatsAPI.coeftableFunction
StatsAPI.coeftable(model::DynamicPanelResult; level::Real=0.95)

Summarize the coefficients of a dynamic panel GMM model.

Arguments

  • model::DynamicPanelResult: Fitted dynamic panel model.
  • level::Real=0.95: Confidence level for intervals (default 0.95).

Returns

  • StatsBase.CoefTable: Table with columns Estimate, Std. Error, z value, Pr(>|z|), Lower, Upper, including significance stars for p-values.
source
DynamicPanelModels.formulaFunction
formula(model::DynamicPanelResult)

Return the formula used for estimation from the model metadata.

formula is not part of StatsAPI (it belongs to StatsModels.jl); this package defines and exports its own top-level formula function instead.

Arguments

  • model::DynamicPanelResult: Model result object.

Returns

  • Any: The stored formula from metadata[:formula], or "N/A" if not available.
source

Diagnostics and Tests

DynamicPanelModels.sargan_testFunction
sargan_test(model::DynamicPanelResult) -> DynamicPanelTest

Compute the Hansen/Sargan J-test for overidentifying restrictions in a dynamic panel model.

Arguments

  • model::DynamicPanelResult: The fitted dynamic panel model containing coefficient estimates and test statistics.

Returns

  • DynamicPanelTest: A struct with the test name, J-statistic, degrees of freedom, and p-value.
source
DynamicPanelModels.ar_testFunction
ar_test(model::DynamicPanelResult, order::Int, id::Vector, time::Vector)

Perform the Arellano–Bond test for serial correlation of order order (AR(order)).

Arguments

  • model::DynamicPanelResult: Fitted dynamic panel model containing residuals, regressors, and variance-covariance matrix.
  • order::Int: Order m of the autocorrelation test.
  • id::Vector: Vector of panel identifiers.
  • time::Vector: Vector of time indices corresponding to each observation.

Returns

  • DynamicPanelTest: Test result including the test name, z-statistic, and p-value.
source
ar_test(model::DynamicPanelResult, order::Int)

Retrieve a previously computed Arellano–Bond autocorrelation test of the given order for a dynamic panel GMM model. AR tests are cached in model.metadata[:ar_tests] the first time diagnose(model; id, time) or ar_test(model, order, id, time) is run.

Arguments

  • model::DynamicPanelResult: Model result containing AR test information.
  • order::Int: Autocorrelation order to test (e.g., 1 for AR(1), 2 for AR(2)).

Returns

  • DynamicPanelTest: The cached AR(order) test result.

Errors

Throws an error if the AR test for order has not yet been computed for this model.

source
DynamicPanelModels.wald_testFunction
wald_test(model::DynamicPanelResult, R::Matrix{Float64}, r::Vector{Float64})

Performs a Wald test on the coefficients of a DynamicPanelResult model.

Arguments

  • model::DynamicPanelResult: The estimated dynamic panel model containing coefficients and variance-covariance matrix.
  • R::Matrix{Float64}: Restriction matrix specifying linear constraints on the coefficients.
  • r::Vector{Float64}: Vector of hypothesized values corresponding to the restrictions.

Returns

  • DynamicPanelTest: Struct containing the test name, Wald statistic, degrees of freedom, and p-value.
source
DynamicPanelModels.goodness_of_fitFunction
goodness_of_fit(model::DynamicPanelResult) -> Float64

Calculates the goodness-of-fit (R²) for a DynamicPanelResult model.

Arguments

  • model::DynamicPanelResult: The dynamic panel model result object containing observed and fitted values.

Returns

  • Float64: The R² value representing the proportion of variance explained by the model.
source
DynamicPanelModels.check_proliferationFunction
check_proliferation(model::DynamicPanelResult) -> String

Checks for potential instrument proliferation in a dynamic panel model.

Arguments

  • model::DynamicPanelResult: The fitted dynamic panel model containing the number of instruments (n_instruments) and groups (n_groups).

Returns

  • String: A message indicating whether the number of instruments is acceptable or exceeds the number of groups, with a warning if proliferation may bias results.
source
DynamicPanelModels.jarque_bera_testFunction
jarque_bera_test(model::DynamicPanelResult)

Performs the Jarque-Bera test for normality on the residuals of a DynamicPanelResult model.

Arguments

  • model::DynamicPanelResult: The fitted dynamic panel model whose residuals are tested.

Returns

  • DynamicPanelTest: A structure containing the test name, test statistic, degrees of freedom, and p-value.
source
DynamicPanelModels.diagnoseFunction
diagnose(model::DynamicPanelResult; id=nothing, time=nothing)

Run GMM diagnostics on a DynamicPanelResult object and return a dictionary of results.

Arguments

  • model::DynamicPanelResult: The fitted dynamic panel model to diagnose.
  • id: Optional vector identifying individual units for AR tests.
  • time: Optional vector identifying time periods for AR tests.

Returns

  • Dict{Symbol, Any}: Contains results of Sargan test, AR tests (if id and time provided), Jarque-Bera test, and pseudo R².
source
DynamicPanelModels.diff_hansen_testFunction
diff_hansen_test(restricted::DynamicPanelResult, unrestricted::DynamicPanelResult) -> DynamicPanelTest

Difference-in-Hansen (C statistic) test for the validity of a subset of instruments, following standard GMM dynamic panel practice (Roodman, 2009) — the panel-data analogue of a Durbin-Wu-Hausman test for GMM instrument subsets.

restricted and unrestricted must be fit with the same estimator (both DifferenceGMM or both SystemGMM) on the same transformed sample (same y/X/n_obs) — e.g. the same model fit with and without additional exog instruments, or with different max_lags/collapse settings. unrestricted must use a strictly larger, nested instrument set. This test is not valid for comparing DifferenceGMM against SystemGMM: System GMM adds level equations and therefore changes the estimating equations and sample, not just the instrument set, so the two are not nested in the required sense.

Under H0 that the extra instruments used only in unrestricted are valid (exogenous), the test statistic

C = J_restricted - J_unrestricted

is asymptotically χ² distributed with degrees of freedom equal to the difference in the number of overidentifying restrictions between the two models. A large, significant C statistic indicates that the additional instruments in unrestricted are not valid.

Because J_restricted and J_unrestricted are each computed with their own independently-estimated two-step weighting matrix (rather than a single common one), C is only guaranteed non-negative asymptotically; in finite samples — especially with many instruments — it can come out slightly negative. This is a well-documented artifact of the two-step weighting matrix, not a sign of error (Roodman, 2009); such cases are reported as strong non-rejection of H0 (C clipped to 0, p-value = 1.0) rather than as NaN.

Arguments

  • restricted::DynamicPanelResult: Model estimated with the smaller instrument set.
  • unrestricted::DynamicPanelResult: Model estimated with the larger (nested) instrument set.

Returns

  • DynamicPanelTest: Test name "Difference-in-Hansen (C)", the C statistic, its degrees of freedom, and p-value.

Errors

Throws an error if the two models were not fit on the same sample (n_obs differs) or if unrestricted does not have strictly more instruments than restricted.

source