code: def test_cov_cluster_2groups():
      # comparing cluster robust standard errors to Peterson
      # requires Petersen's test_data
      # http://www.kellogg.northwestern.edu/faculty/petersen
      #      .../htm/papers/se/test_data.txt
      import os
  
      cur_dir = os.path.abspath(os.path.dirname(__file__))
      fpath = os.path.join(cur_dir, "test_data.txt")
      pet = np.genfromtxt(fpath)
      endog = pet[:, -1]
      group = pet[:, 0].astype(int)
      time = pet[:, 1].astype(int)
      exog = add_constant(pet[:, 2])
      res = OLS(endog, exog).fit()
  
      cov01, covg, covt = sw.cov_cluster_2groups(
          res, group, group2=time
      )
  
      # Reference number from Petersen
      # http://www.kellogg.northwestern.edu/faculty/petersen/htm
      #       .../papers/se/test_data.htm
  
      bse_petw = [0.0284, 0.0284]
      bse_pet0 = [0.0670, 0.0506]
      bse_pet1 = [0.0234, 0.0334]  # year
      bse_pet01 = [0.0651, 0.0536]  # firm and year
      bse_0 = sw.se_cov(covg)
      bse_1 = sw.se_cov(covt)
      bse_01 = sw.se_cov(cov01)
      # print res.HC0_se, bse_petw - res.HC0_se
      # print bse_0, bse_0 - bse_pet0
      # print bse_1, bse_1 - bse_pet1
      # print bse_01, bse_01 - bse_pet01
      assert_almost_equal(bse_petw, res.HC0_se, decimal=4)
      assert_almost_equal(bse_0, bse_pet0, decimal=4)
      assert_almost_equal(bse_1, bse_pet1, decimal=4)
      assert_almost_equal(bse_01, bse_pet01, decimal=4)
  
imports: import numpy
  from numpy.testing import assert_almost_equal, assert_allclose
  from statsmodels.regression.linear_model import OLS
  from statsmodels.tools.tools import add_constant
  import statsmodels.stats.sandwich_covariance
label_desc: Use image node_id 1 for calling a global function with example usage: test_cov_cluster_2groups() without return types