def cov_nw_groupsum(results, nlags, time, weights_func=weights_bartlett, use_correction=0):
 (xu, hessian_inv) = _get_sandwich_arrays(results)
 S_hac = S_hac_groupsum(xu, time, nlags=nlags, weights_func=weights_func)
 cov_hac = _HCCM2(hessian_inv, S_hac)
 if use_correction:
  (nobs, k_params) = xu.shape
  if (use_correction == 'hac'):
   cov_hac *= (nobs / float((nobs - k_params)))
  elif (use_correction in ['c', 'cluster']):
   n_groups = len(np.unique(time))
   cov_hac *= (n_groups / (n_groups - 1.0))
   cov_hac *= ((nobs - 1.0) / float((nobs - k_params)))
 return cov_hac

def cov_nw_groupsum ( results , nlags , time , weights_func = weights_bartlett , use_correction = 0 ) : ( xu , hessian_inv ) = _get_sandwich_arrays ( results ) S_hac = S_hac_groupsum ( xu , time , nlags = nlags , weights_func = weights_func ) cov_hac = _HCCM2 ( hessian_inv , S_hac ) if use_correction : ( nobs , k_params ) = xu . shape if ( use_correction == 'hac' ) : cov_hac *= ( nobs / float ( ( nobs - k_params ) ) ) elif ( use_correction in [ 'c' , 'cluster' ] ) : n_groups = len ( np . unique ( time ) ) cov_hac *= ( n_groups / ( n_groups - 1.0 ) ) cov_hac *= ( ( nobs - 1.0 ) / float ( ( nobs - k_params ) ) ) return cov_hac
driscoll and kraay panel robust covariance matrix robust covariance matrix for panel data of driscoll and kraay .