code: def test_stata():
      # Test the cusum and cusumsq statistics against Stata (cusum6)
      mod = RecursiveLS(endog, exog, loglikelihood_burn=3)
      with pytest.warns(UserWarning):
          res = mod.fit()
      d = max(res.nobs_diffuse, res.loglikelihood_burn)
  
      assert_allclose(
          res.resid_recursive[3:],
          results_stata.iloc[3:]["rr"],
          atol=1e-5,
          rtol=1e-5,
      )
      assert_allclose(
          res.cusum, results_stata.iloc[3:]["cusum"], atol=1e-5
      )
      assert_allclose(
          res.cusum_squares, results_stata.iloc[3:]["cusum2"], atol=1e-5
      )
  
      actual_bounds = res._cusum_significance_bounds(
          alpha=0.05, ddof=0, points=np.arange(d + 1, res.nobs + 1)
      )
      desired_bounds = results_stata.iloc[3:][["lw", "uw"]].T
      assert_allclose(actual_bounds, desired_bounds, atol=1e-5)
  
      # Note: Stata uses a set of tabulated critical values whereas we use an
      # approximation formula, so this test is quite imprecise
      actual_bounds = res._cusum_squares_significance_bounds(
          alpha=0.05, points=np.arange(d + 1, res.nobs + 1)
      )
      desired_bounds = results_stata.iloc[3:][["lww", "uww"]].T
      assert_allclose(actual_bounds, desired_bounds, atol=1e-2)
  
imports: import os
  import numpy
  from numpy.testing import assert_allclose, assert_equal, assert_raises
  import pandas
  import pytest
  from scipy.stats import norm
  from statsmodels.datasets import macrodata
  from statsmodels.genmod.api import GLM
  from statsmodels.regression.linear_model import OLS
  from statsmodels.regression.recursive_ls import RecursiveLS
  from statsmodels.stats.diagnostic import recursive_olsresiduals
  from statsmodels.tools import add_constant
  from statsmodels.tools.eval_measures import aic, bic
  from statsmodels.tools.sm_exceptions import ValueWarning
label_desc: Use image node_id 12 for calling a global function with example usage: test_stata() without return types