RainbowStats command reference

GROUPED_CROSS_SECTION

Compare a pooled county regression with state-aware models, test whether state membership matters, and inspect whether the apparent fit comes from differences between states or relationships within states.

Syntax

GROUPED_CROSS_SECTION(crossSection)

The argument must be a CrossSectionOperator, normally produced by CROSS_SECTION. County FIPS row keys are resolved through USCountyRegistry, and the first two FIPS digits identify each state.

CountyModel=CROSS_SECTION(CountyData,20221231)
Grouped=GROUPED_CROSS_SECTION(CountyModel)
SLIDESHOW(Grouped)
Pass the original cross section. Do not first apply STATE_FIXED_EFFECTS. The grouped operator creates its own state indicators; passing an already-expanded model duplicates the dummy variables and can produce a singular regression matrix.

What the command estimates

ModelPurposeInterpretation
Pooled OLSIgnores state membership.Describes the combined cross section as if all counties came from one population.
State indicators onlyUses state membership without the substantive predictors.Measures the raw separation attributable to differences in state means.
State fixed effectsAdds states − 1 indicators to the predictors.Allows different state intercepts while imposing common predictor slopes.
Within-state regressionDemeans the outcome and predictors inside each state.Shows explanatory power after state means have been removed. Its slopes should match the fixed-effects slopes.
State interactionsInteracts each predictor with each non-reference state.Tests whether predictor slopes vary by state as well as intercepts.

ANOVA and model tests

The output distinguishes two related but different questions:

  1. One-way state ANOVA: do the unadjusted state means of the outcome differ?
  2. Nested-model F-tests: do state intercepts improve the regression after controlling for the predictors, and do state-specific slopes improve it further?

The distribution chart places every state's density histogram in one visual. Because density—not county count—is plotted, states with different numbers of counties remain comparable. Separation between the histograms provides an immediate visual explanation of a small ANOVA p-value.

The fixed-effects and interaction regressions center predictors at their overall sample means. Thus Constant (IA at predictor means) is the fitted Iowa outcome for a county with typical predictor values. A coefficient such as State FE: WA is the estimated Washington–Iowa difference at those same predictor values.

Slides produced

  1. Grouped cross-section audit
  2. State summary and variable means
  3. Pooled and grouped model comparison
  4. One-way ANOVA and nested-model tests
  5. Outcome distributions by state
  6. State fixed-effects regression
  7. Within-state regression
  8. State-specific slopes and interaction test
  9. Fixed-effects actual versus predicted
  10. Within-state actual versus predicted
  11. Sorted fixed-effects residuals and labeled outliers

Extract individual results

RequestReturned result
summary or auditData audit and state summary
comparison or r2Comparison of pooled and grouped models
anovaOne-way ANOVA and nested-model F-tests
distributionOverlaid state density histograms
fixed_effects or feState fixed-effects regression
withinWithin-state regression
interactions or slopesState-specific slopes and joint interaction test
actual_vs_fitted or fitFixed-effects actual-versus-predicted chart
within_fitWithin-state actual-versus-predicted chart
residuals or outliersSorted fixed-effects residual chart
ANOVA=EXTRACT(Grouped,anova)
Distribution=EXTRACT(Grouped,distribution)
FixedEffects=EXTRACT(Grouped,fixed_effects)
WithinState=EXTRACT(Grouped,within)
Outliers=EXTRACT(Grouped,outliers)
SLIDESHOW(ANOVA,Distribution,FixedEffects,WithinState,Outliers)

Complete CDC county example

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)

CountyData=LIST(Mental,Isolation,Food,Income)
CountyModel=CROSS_SECTION(CountyData,20221231)
Grouped=GROUPED_CROSS_SECTION(CountyModel)
SLIDESHOW(Grouped)

How to read the results

Data handling and cautions