*! _fjcoint_cv_trace.ado
*! 5% critical values for Fourier-Trace test
*! Source: Pascalau, Lee, Nazlioglu & Lu (2022), Online Appendix Tables 1-8
*! Part of fjcoint package

program define _fjcoint_cv_trace, rclass
  version 14.0

  args option model f m

  * option: 1=single, 2=cumulative
  * model:  1=Constant, 2=Trend, 3=RC, 4=RT
  * f: frequency (1-5)
  * m: number of variables (1-5)

  if `m' < 1 | `m' > 5 {
    di as err "number of variables must be between 1 and 5"
    exit 198
  }
  if `f' < 1 | `f' > 5 {
    di as err "frequency must be between 1 and 5"
    exit 198
  }

  tempname cv_ft

  if `option' == 1 {
    * Single frequency
    if `model' == 1 {
      matrix `cv_ft' = ( ///
        14.30840, 28.18929, 46.02544, 67.68133, 93.91098 \ ///
        10.51359, 22.60040, 38.91366, 60.67533, 86.50896 \ ///
         9.40690, 20.71316, 35.77095, 56.38972, 81.37919 \ ///
         8.85902, 19.73940, 34.62302, 53.82681, 78.36771 \ ///
         8.62743, 19.13382, 33.64254, 52.29388, 76.01140 )
    }
    else if `model' == 2 {
      matrix `cv_ft' = ( ///
        18.09039, 35.55617, 56.49866, 81.12916, 109.17405 \ ///
        15.86571, 31.17837, 50.74269, 74.78432, 102.38793 \ ///
        14.21382, 28.55989, 46.79052, 69.25963,  96.24529 \ ///
        13.22626, 26.89691, 44.13739, 66.35955,  92.48682 \ ///
        12.58547, 25.83584, 43.00055, 64.33425,  89.88038 )
    }
    else if `model' == 3 {
      matrix `cv_ft' = ( ///
        14.74275, 29.58587, 48.92995, 71.81054, 99.11298 \ ///
        11.22645, 24.46542, 42.11900, 65.00828, 91.92876 \ ///
        10.24255, 22.83348, 39.16091, 60.81107, 86.83963 \ ///
         9.85987, 21.88533, 37.84303, 58.23366, 83.59189 \ ///
         9.53509, 21.32864, 36.94860, 56.82161, 81.62480 )
    }
    else if `model' == 4 {
      matrix `cv_ft' = ( ///
        18.90748, 37.47358, 59.39504, 85.16574, 114.20359 \ ///
        16.37934, 33.03774, 53.42384, 78.86507, 107.71686 \ ///
        14.82827, 30.20683, 49.80522, 73.87547, 101.74087 \ ///
        13.83531, 28.82023, 47.18157, 70.47044,  97.87634 \ ///
        13.28540, 27.72151, 45.80354, 68.30843,  95.16862 )
    }
  }
  else {
    * Cumulative frequency
    if `model' == 1 {
      matrix `cv_ft' = ( ///
        14.30840, 28.18929, 46.02544, 67.68133,  93.91098 \ ///
        19.73892, 37.92253, 59.84259, 86.58413, 117.05128 \ ///
        25.34511, 47.78119, 73.55901, 104.83568, 140.70307 \ ///
        30.39381, 57.38707, 87.96552, 123.44607, 163.66453 \ ///
        35.78632, 67.11283, 102.21303, 142.35412, 187.47393 )
    }
    else if `model' == 2 {
      matrix `cv_ft' = ( ///
        18.09039, 35.55617, 56.49866,  81.12916, 109.17405 \ ///
        24.65593, 46.81503, 72.96398, 103.00425, 136.41383 \ ///
        30.28825, 58.41858, 89.82574, 125.17419, 163.80433 \ ///
        36.91493, 69.48224, 106.81500, 145.99311, 190.71159 \ ///
        42.74488, 80.94095, 122.92470, 168.06434, 217.45626 )
    }
    else if `model' == 3 {
      matrix `cv_ft' = ( ///
        18.09039, 35.55617, 56.49866,  81.12916, 109.17405 \ ///
        24.65593, 46.81503, 72.96398, 103.00425, 136.41383 \ ///
        30.28825, 58.41858, 89.82574, 125.17419, 163.80433 \ ///
        36.91493, 69.48224, 106.81500, 145.99311, 190.71159 \ ///
        42.74488, 80.94095, 122.92470, 168.06434, 217.45626 )
    }
    else if `model' == 4 {
      matrix `cv_ft' = ( ///
        17.36134, 34.86245, 56.15881,  81.32806, 111.08734 \ ///
        25.51318, 48.98605, 76.33016, 109.20236, 144.88705 \ ///
        32.82653, 62.79299, 96.91238, 135.64276, 179.15233 \ ///
        40.45318, 77.00024, 116.93661, 162.08337, 212.44297 \ ///
        47.73399, 90.84489, 137.39421, 189.81457, 246.32093 )
    }
  }

  * Return the critical value for this frequency and rank dimension
  return scalar cv = `cv_ft'[`f', `m']
  return matrix cv_matrix = `cv_ft'

end