Syntax
| Argument | Required type | Meaning |
|---|---|---|
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. |
CrossSectionOperator. Use SLIDESHOW for the complete report or EXTRACT for an individual table or graphic.
How the data are organized
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.
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:
- Data audit — requested date, number of variables, observation keys, complete rows, missing rows, and outcome.
- Observations — the assembled cross-sectional data table.
- Summary statistics — N, mean, standard deviation, minimum, and maximum for each variable.
- Correlation matrix — pairwise correlations among the variables.
- OLS regression — coefficients, standard errors, t-statistics, R², adjusted R², and sample size.
- Actual versus predicted — fitted values against observed outcomes, with a 45-degree reference line.
- Sorted residuals — residuals ordered from negative to positive, with state or group colors.
- Residual distribution — a histogram with a fitted normal reference curve.
- 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.
| Expression | Returned 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
- Cross-sectional, not causal. Coefficients describe conditional associations at one date. They do not establish that a predictor caused the outcome.
- Counties are places, not people. A county-level relationship should not be interpreted as an individual-level relationship.
- Geography may matter. State policies, urbanization, measurement practices, and other omitted differences can influence coefficients and residuals.
- R² is descriptive. A high R² may reflect a homogeneous sample or geographic structure; compare samples and inspect residuals.
- The normal curve is a reference. The residual histogram is a diagnostic aid, not proof that the regression assumptions hold.
- Watch for collinearity. Strongly related predictors can make coefficient estimates unstable even when overall fit appears good.
Common messages
| Message | Likely cause | What 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. |