code: def sum_outer_product_loop(x, group_iter):
      """sum outerproduct dot(x_i, x_i.T) over individuals
  
      loop version
  
      """
  
      mom = 0
      for g in group_iter():
          x_g = x[g]
          # print 'x_g.shape', x_g.shape
          mom += np.outer(x_g, x_g)
  
      return mom
  
imports: import numpy
  from statsmodels.regression.linear_model import OLS, GLS
  from statsmodels.tools.grouputils import GroupSorted
label_desc: Use image node_id 1 for calling a global function with example usage: sum_outer_product_loop(x, group_iter) and returns: mom