code: def attach_moment_conditions(cls):
      # TODO: a better structure ?
      res_ols = cls.res_ols
      # assumes x = column_stack([x0, x1])
      x = cls.exog_full
      # x0 = cls.res_ols.model.exog  # not used here
      x1 = cls.exog_add
  
      nobs, k_constraints = x1.shape
  
      # TODO: cleanup after initial copy past
      moms_obs = res_ols.resid[:, None] * x
      moms = moms_obs.sum(0)
      cov_moms = res_ols.mse_resid * x.T.dot(
          x
      )  # np.linalg.inv(x.T.dot(x))
      cov_moms *= res_ols.df_resid / nobs
  
      # weights used for GMM to replicate OLS
      weights = np.linalg.inv(cov_moms)
      # we do not use last two variables
      weights[:, -k_constraints:] = 0
      weights[-k_constraints:, :] = 0
  
      k_moms = moms.shape[0]
      # TODO: Newey has different versions that all produce the same result
      #       in example
      L = np.eye(k_moms)[
          -k_constraints:
      ]  # .dot(np.linalg.inv(cov_moms))
  
      moms_deriv = cov_moms[:, :-k_constraints]
  
      covm = moms_obs.T.dot(moms_obs)
  
      # attach
      cls.nobs = nobs
      cls.moms = moms
      cls.moms_obs = moms_obs
      cls.cov_moms = cov_moms
      cls.covm = covm
      cls.moms_deriv = moms_deriv
      cls.weights = weights
      cls.L = L
  
file_path: statsmodels/statsmodels/stats/tests/test_diagnostic_other.py
imports: import numpy
  from numpy.testing import assert_allclose
  from statsmodels.regression.linear_model import OLS
  from statsmodels.stats._diagnostic_other import CMTNewey, CMTTauchen
  import statsmodels.stats._diagnostic_other
label_desc: Use image node_id 2 for calling the TestCMTOLS obj's underlying member method code with example usage: obj.attach_moment_conditions(cls) without return types