RainbowStats command reference

CROSS_SECTION

Build a dated cross section from a list of named series, calculate descriptive statistics and correlations, and estimate an ordinary least-squares regression.

Syntax

CROSS_SECTION(data, yyyyMMdd)
ArgumentRequired typeMeaning
data Data list A list of cross-sectional series. The first variable becomes the regression outcome; all remaining variables become predictors.
yyyyMMdd Date integer The observation date, written without quotation marks—for example, 20221231.
Result The command returns a CrossSectionOperator. Use SLIDESHOW for the complete report or EXTRACT for an individual table or graphic.

How the data are organized

1. Load series
2. Match observation keys
3. Select the date
4. Estimate the model

Each series must identify both a variable and an observation, such as a county. Series returned by LOOP_US_COUNTY already follow the required convention. RainbowStats can also identify observations from a series name containing " - ", where the text before the separator is the variable name and the text after it is the observation label.

The requested date is matched exactly. For annual series, RainbowStats also accepts an observation from the same calendar year when different sources assign different dates to that annual value.

Variable order matters In Data=LIST(Mental,Isolation,Food,Income), Mental is the dependent variable. The other three variables are regressors.

Complete example: Washington and Iowa counties

This example examines county-level frequent mental distress using social isolation, food insecurity, and median household income relative to the United States. The cross section is dated December 31, 2022.

WAMental=LOOP_US_COUNTY(CDC(MHLTH_$$_AGEADJPRV),"WA")
IAMental=LOOP_US_COUNTY(CDC(MHLTH_$$_AGEADJPRV),"IA")
Mental=LIST(WAMental,IAMental)

WAIsolation=LOOP_US_COUNTY(CDC(ISOLATION_$$_AGEADJPRV),"WA")
IAIsolation=LOOP_US_COUNTY(CDC(ISOLATION_$$_AGEADJPRV),"IA")
Isolation=LIST(WAIsolation,IAIsolation)

WAFood=LOOP_US_COUNTY(CDC(FOODINSECU_$$_AGEADJPRV),"WA")
IAFood=LOOP_US_COUNTY(CDC(FOODINSECU_$$_AGEADJPRV),"IA")
Food=LIST(WAFood,IAFood)

WAIncome=LOOP_US_COUNTY(
  SET_NAME(MHIWA$$A052NCEN%MHIUS00000A052NCEN,
  "Median Income Relative to U.S. - $$"),"WA")
IAIncome=LOOP_US_COUNTY(
  SET_NAME(MHIIA$$A052NCEN%MHIUS00000A052NCEN,
  "Median Income Relative to U.S. - $$"),"IA")
Income=LIST(WAIncome,IAIncome)

Data=LIST(Mental,Isolation,Food,Income)
C=CROSS_SECTION(Data,20221231)
SLIDESHOW(C)

Slideshow output

When at least two variables are available, SLIDESHOW(C) produces a nine-panel report:

  1. Data audit — requested date, number of variables, observation keys, complete rows, missing rows, and outcome.
  2. Observations — the assembled cross-sectional data table.
  3. Summary statistics — N, mean, standard deviation, minimum, and maximum for each variable.
  4. Correlation matrix — pairwise correlations among the variables.
  5. OLS regression — coefficients, standard errors, t-statistics, R², adjusted R², and sample size.
  6. Actual versus predicted — fitted values against observed outcomes, with a 45-degree reference line.
  7. Sorted residuals — residuals ordered from negative to positive, with state or group colors.
  8. Residual distribution — a histogram with a fitted normal reference curve.
  9. Largest residuals — the ten observations with the largest absolute residuals.

Extract individual results

Extraction keys may be written without quotation marks in a RainbowStats script.

ExpressionReturned result
EXTRACT(C,data)Numeric cross-sectional matrix
EXTRACT(C,summary)Summary-statistics table
EXTRACT(C,correlation)Correlation matrix
EXTRACT(C,regression)OLS regression table
EXTRACT(C,actual_vs_fitted)Actual-versus-predicted graphic
EXTRACT(C,residual_plot)Sorted-residual graphic
EXTRACT(C,residual_distribution)Residual histogram and normal reference curve
EXTRACT(C,residuals)Table of the ten largest absolute residuals
EXTRACT(C,slideshow)Complete slideshow

Graphic aliases

fit and actual_fitted select the actual-versus-predicted chart; residual_chart selects the sorted residuals; and bell_curve or histogram selects the residual distribution.

Missing observations

Summary statistics use every finite observation available for each variable. Correlations use all finite pairs available for the two variables being compared. The regression and its diagnostic graphics use complete cases: a county is included only when every model variable has a finite value.

A state or source with no observations for a requested series contributes nothing to that data list. Always inspect the audit panel before interpreting the regression; the displayed regression sample size can therefore be smaller than the total number of observation keys.

Interpretation and cautions

Common messages

MessageLikely causeWhat to check
Not enough complete observations for regression. Too few rows remain after missing values are removed. Review the audit table, source coverage, requested date, and number of predictors.
Cannot derive a cross-sectional key. A series lacks a recognized CDC/FIPS code and its name does not contain " - ". Use SET_NAME so each series has the form Variable - Observation.
Duplicate observation. Two series resolve to the same observation and variable. Remove the duplicate or correct its series name/code.
Regression failed. The design matrix may be singular or otherwise unsuitable for OLS. Remove redundant predictors and verify that each predictor varies across observations.