statsmodels.stats.sandwich_covariance.cov_nw_panel¶

statsmodels.stats.sandwich_covariance.
cov_nw_panel
(results, nlags, groupidx, weights_func=<function weights_bartlett>, use_correction='hac')[source]¶ Panel HAC robust covariance matrix
Assumes we have a panel of time series with consecutive, equal spaced time periods. Data is assumed to be in long format with time series of each individual stacked into one array. Panel can be unbalanced.
 Parameters
 resultsresult instance
result of a regression, uses results.model.exog and results.resid TODO: this should use wexog instead
 nlagsint or None
Highest lag to include in kernel window. Currently, no default because the optimal length will depend on the number of observations per crosssectional unit.
 groupidxlist of tuple
each tuple should contain the start and end index for an individual. (groupidx might change in future).
 weights_funccallable
weights_func is called with nlags as argument to get the kernel weights. default are Bartlett weights
 use_correction‘cluster’ or ‘hac’ or False
If False, then no small sample correction is used. If ‘cluster’ (default), then the same correction as in cov_cluster is used. If ‘hac’, then the same correction as in single time series, cov_hac is used.
 Returns
 covndarray, (k_vars, k_vars)
HAC robust covariance matrix for parameter estimates
Notes
For nlags=0, this is just White covariance, cov_white. If kernel is uniform, weights_uniform, with nlags equal to the number of observations per unit in a balance panel, then cov_cluster and cov_hac_panel are identical.
Tested against STATA newey command with same defaults.
Options might change when other kernels besides Bartlett and uniform are available.