RainbowStats Command Reference

BEST_REGRESSION

Search a collection of candidate explanatory variables and return the ordinary least-squares regression containing the N variables that provide the best in-sample fit.

Syntax

BEST_REGRESSION(DataSeriesList, N)
Argument Description
DataSeriesList A list of aligned series. The first series is the dependent variable; every remaining series is a candidate explanatory variable.
N The exact number of explanatory variables to include in the returned model.

The command returns a standard RainbowStats regression result, including coefficients, standard errors, test statistics, goodness-of-fit measures, and residual diagnostics.

How the search works

Internally, RainbowStats uses the VariableSearch class. This is an exhaustive best-subset search: it evaluates every possible combination of exactly N predictors rather than adding variables one at a time.

  1. Align the series to their common date range.
  2. Generate every combination of N candidate predictors.
  3. Reject combinations whose design matrix is singular.
  4. Keep the combination with the smallest residual sum of squares.

Each admissible combination is estimated by ordinary least squares with a constant. The winning model is the one that minimizes RSS = Σ(y − ŷ)². Because every candidate model contains the same number of explanatory variables and uses the same observations, minimizing RSS is equivalent to maximizing the in-sample R².

Exact means exact. If N is 3, the search returns the best model containing exactly three explanatory variables. It does not stop at one or two variables merely because a smaller model is more parsimonious.

Example


L=SAME_DATE_RANGE(LIST(UNRATE,DGS10,TCU,GDP,CORESTICKM159SFRBATL))
LD=LOGDIFF(L)
BEST_REGRESSION(LD,2)
BEST_COVID_REGRESSION(LD,2)

The series are first aligned to a common date range and then converted to log differences. Because UNRATE is first in the list, its transformed series is the dependent variable. RainbowStats examines every two-variable combination drawn from DGS10, TCU, GDP, and CORESTICKM159SFRBATL.

BEST_REGRESSION returns the best ordinary specification, while BEST_COVID_REGRESSION repeats the exercise using the COVID-adjusted regression. Running both makes it easy to see whether the pandemic period materially changes the selected model or its estimated relationships.

With four candidates and two selected variables, each search considers C(4,2) = 6 combinations. With 20 candidates and five selected variables, it must estimate C(20,5) = 15,504 regressions.

BEST_COVID_REGRESSION(DataSeriesList, N)

Use BEST_COVID_REGRESSION when the sample includes the exceptional pandemic disruption and an ordinary regression may treat that episode as if it reflected the usual economic relationship. It accepts the same arguments and returns the same style of regression output as BEST_REGRESSION.

Prefer comparison to automatic adjustment. Run the ordinary and COVID-adjusted commands together. If they choose different variables or produce materially different coefficients, the pandemic treatment is an important part of the conclusion and should be reported.

Good practice

Prepare economically meaningful inputs

The command searches the series you provide; it does not decide whether levels, differences, growth rates, lags, or other transformations are economically appropriate. Prepare the candidate list before running the search.

Keep the candidate set focused

The number of models grows rapidly with the size of the candidate set. A focused list runs faster and makes the final model easier to interpret. The search count is:

number of models = C(P, N)

Here, P is the number of candidate explanatory variables and N is the number selected.

Use the result as evidence, not automatic proof

A variable can improve in-sample fit without having a causal relationship with the dependent variable. Inspect coefficient signs, residuals, stability, timing, and the economic logic of the selected model.

Selection changes inference. The reported regression statistics are calculated after searching many competing models. Conventional p-values and confidence intervals do not account for that search and may appear more convincing than they really are. Whenever possible, confirm the result on data that were not used to select the variables.

Implementation notes