def _neweywestcov(resid, x):
 nobs = resid.shape[0]
 nlags = int(round((4 * ((nobs / 100.0) ** (2 / 9.0)))))
 hhat = (resid * x.T)
 xuux = np.dot(hhat, hhat.T)
 for lag in range(nlags):
  za = np.dot(hhat[:, lag:nobs], hhat[:, :(nobs - lag)].T)
  w = (1 - (lag / (nobs + 1.0)))
  xuux = (xuux + np.dot(w, (za + za.T)))
 xtxi = np.linalg.inv(np.dot(x.T, x))
 covbNW = np.dot(xtxi, np.dot(xuux, xtxi))
 return covbNW

def _neweywestcov ( resid , x ) : nobs = resid . shape [ 0 ] nlags = int ( round ( ( 4 * ( ( nobs / 100.0 ) ** ( 2 / 9.0 ) ) ) ) ) hhat = ( resid * x . T ) xuux = np . dot ( hhat , hhat . T ) for lag in range ( nlags ) : za = np . dot ( hhat [ : , lag : nobs ] , hhat [ : , : ( nobs - lag ) ] . T ) w = ( 1 - ( lag / ( nobs + 1.0 ) ) ) xuux = ( xuux + np . dot ( w , ( za + za . T ) ) ) xtxi = np . linalg . inv ( np . dot ( x . T , x ) ) covbNW = np . dot ( xtxi , np . dot ( xuux , xtxi ) ) return covbNW
did not run yet from regstats2 :: if idx % hac l = round(4*^); % l = nobs^ .