API Reference
DynamicPanelModels.AbstractDynamicPanelModelDynamicPanelModels.AndersonHsiaoDynamicPanelModels.DifferenceGMMDynamicPanelModels.DynamicPanelResultDynamicPanelModels.DynamicPanelTestDynamicPanelModels.SystemGMMDynamicPanelModels.ar_testDynamicPanelModels.build_instrumentsDynamicPanelModels.check_proliferationDynamicPanelModels.diagnoseDynamicPanelModels.diff_hansen_testDynamicPanelModels.estimateDynamicPanelModels.formulaDynamicPanelModels.get_diff_dataDynamicPanelModels.goodness_of_fitDynamicPanelModels.is_robustDynamicPanelModels.is_windmeijerDynamicPanelModels.jarque_bera_testDynamicPanelModels.lagDynamicPanelModels.ngroupsDynamicPanelModels.ninstrumentsDynamicPanelModels.parse_formulaDynamicPanelModels.sargan_testDynamicPanelModels.wald_testStatsAPI.coefStatsAPI.coeftableStatsAPI.confintStatsAPI.dofStatsAPI.dof_residualStatsAPI.fitStatsAPI.fittedStatsAPI.nobsStatsAPI.predictStatsAPI.residualsStatsAPI.stderrorStatsAPI.vcov
Model Types
DynamicPanelModels.DifferenceGMM — Type
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 iftrue.steps::Int=1: Number of GMM steps (1= one-step,2= two-step). Must be ≥ 1.windmeijer::Bool=true: Apply Windmeijer finite-sample correction whenrobust=true.
DynamicPanelModels.SystemGMM — Type
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 iftrue.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.
DynamicPanelModels.AndersonHsiao — Type
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.
DynamicPanelModels.AbstractDynamicPanelModel — Type
AbstractDynamicPanelModelAbstract supertype representing dynamic panel data model specifications.
DynamicPanelModels.DynamicPanelResult — Type
DynamicPanelResult <: RegressionModelResult 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 whenrobust).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())DynamicPanelModels.DynamicPanelTest — Type
DynamicPanelTestResults 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.
Estimation and Data Handling
StatsAPI.fit — Function
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. aDataFrame, 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)). Supportslag(var[, k|a:b])for lags and the transformslog, log10, log2, exp, sqrt, abs. Seeget_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. Seeget_diff_data.time_effects: Iftrue, include period dummies (exogenous). Seeget_diff_data.transform::fd(first differences, default) or:fod(forward orthogonal deviations, Arellano-Bover; DifferenceGMM only). Seeget_diff_data.kwargs...: Additional keyword arguments passed toestimate— includingsteps,robust,collapse,max_lags,min_lag,max_lag, anddrop_collinear.
Examples
fit(DifferenceGMM(robust=true), df; formula = @formula(y ~ lag(y) + x),
id_col = :id, time_col = :time, exog = ["x"])DynamicPanelModels.estimate — Function
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: EitherDifferenceGMMorSystemGMM.diff_data::NamedTuple: Preprocessed panel data with fields:y: Response vector (differenced if needed)X: Design matrixcoef_names: Names of regressorspanel_info: Row metadata (id,time,is_level)n_obs: Number of observationsid_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 tomodel.steps.robust::Bool: Use robust (cluster-sandwich) standard errors. Defaults tomodel.robust.windmeijer::Bool: Whensteps == 2 && robust, apply the Windmeijer (2005) finite-sample correction instead of the naive two-step sandwich. Defaults tomodel.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 (asxtabond2).
Returns
DynamicPanelResult: Contains coefficients, standard errors, residuals, fitted values, instruments, and diagnostics.
DynamicPanelModels.get_diff_data — Function
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. aDataFrame).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)→xandL.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 incoef_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: Iftrue, addT-2period 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 withX.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 ofX(aligned withcoef_names) that are strictly exogenous.
DynamicPanelModels.parse_formula — Function
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.
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.
DynamicPanelModels.build_instruments — Function
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.
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, optionalis_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.
build_instruments(model::SystemGMM, diff_data::NamedTuple; collapse::Bool=false, max_lags::Int=Inf)Construct the System GMM (Blundell-Bond) instrument matrix by combining:
- Difference equation instruments (lags of Δy)
- 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 mappingid => 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.
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 fromget_diff_data. Any regressors named inexog(seeget_diff_data) are appended as additional instrument columns.kwargs...: Additional keyword arguments (currently ignored).
Returns
SparseMatrixCSC{Float64, Int}: Instrument matrix with one column ofy_{i,t-2}for each differenced observation, plus one column per strictly exogenous regressor.
DynamicPanelModels.lag — Function
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.
DynamicPanelModels.ngroups — Function
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.
DynamicPanelModels.ninstruments — Function
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.
DynamicPanelModels.is_robust — Function
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:trueif robust standard errors were used,falsefor homoskedastic/naive SEs.
DynamicPanelModels.is_windmeijer — Function
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:trueif Windmeijer-corrected standard errors were applied,falseotherwise.
StatsAPI Interface
StatsAPI.coef — Function
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.
StatsAPI.vcov — Function
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.
StatsAPI.stderror — Function
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 containingvcov.
Returns
Vector{Float64}: Standard errors.
StatsAPI.residuals — Function
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.
StatsAPI.fitted — Function
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.
StatsAPI.predict — Function
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.
StatsAPI.nobs — Function
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: Iftrue, returns number of groups; otherwise returns total observations.
Returns
Int: Number of observations or groups.
StatsAPI.dof — Function
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.
StatsAPI.dof_residual — Function
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).
StatsAPI.confint — Function
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.
StatsAPI.coeftable — Function
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 columnsEstimate,Std. Error,z value,Pr(>|z|),Lower,Upper, including significance stars for p-values.
DynamicPanelModels.formula — Function
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 frommetadata[:formula], or"N/A"if not available.
Diagnostics and Tests
DynamicPanelModels.sargan_test — Function
sargan_test(model::DynamicPanelResult) -> DynamicPanelTestCompute 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.
DynamicPanelModels.ar_test — Function
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: Ordermof 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.
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.
DynamicPanelModels.wald_test — Function
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.
DynamicPanelModels.goodness_of_fit — Function
goodness_of_fit(model::DynamicPanelResult) -> Float64Calculates 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.
DynamicPanelModels.check_proliferation — Function
check_proliferation(model::DynamicPanelResult) -> StringChecks 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.
DynamicPanelModels.jarque_bera_test — Function
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.
DynamicPanelModels.diagnose — Function
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 (ifidandtimeprovided), Jarque-Bera test, and pseudo R².
DynamicPanelModels.diff_hansen_test — Function
diff_hansen_test(restricted::DynamicPanelResult, unrestricted::DynamicPanelResult) -> DynamicPanelTestDifference-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_unrestrictedis 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)", theCstatistic, 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.