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
| Model | Purpose | Interpretation |
|---|---|---|
| Pooled OLS | Ignores state membership. | Describes the combined cross section as if all counties came from one population. |
| State indicators only | Uses state membership without the substantive predictors. | Measures the raw separation attributable to differences in state means. |
| State fixed effects | Adds states − 1 indicators to the predictors. | Allows different state intercepts while imposing common predictor slopes. |
| Within-state regression | Demeans 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 interactions | Interacts 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:
- One-way state ANOVA: do the unadjusted state means of the outcome differ?
- 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
- Grouped cross-section audit
- State summary and variable means
- Pooled and grouped model comparison
- One-way ANOVA and nested-model tests
- Outcome distributions by state
- State fixed-effects regression
- Within-state regression
- State-specific slopes and interaction test
- Fixed-effects actual versus predicted
- Within-state actual versus predicted
- Sorted fixed-effects residuals and labeled outliers
Extract individual results
| Request | Returned result |
|---|---|
summary or audit | Data audit and state summary |
comparison or r2 | Comparison of pooled and grouped models |
anova | One-way ANOVA and nested-model F-tests |
distribution | Overlaid state density histograms |
fixed_effects or fe | State fixed-effects regression |
within | Within-state regression |
interactions or slopes | State-specific slopes and joint interaction test |
actual_vs_fitted or fit | Fixed-effects actual-versus-predicted chart |
within_fit | Within-state actual-versus-predicted chart |
residuals or outliers | Sorted 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
- A large increase from pooled to fixed-effects R² indicates that state membership contains important information omitted from the pooled model.
- A significant pooled-versus-fixed-effects F-test supports adding different state intercepts.
- A weak interaction F-test supports the simpler common-slope fixed-effects specification.
- A low within-state R² means that much of the apparent pooled fit is between states rather than among counties within the same state.
- Residual outliers remain substantively important even when state effects substantially improve overall fit.
Data handling and cautions
- Rows missing the outcome or any predictor are removed as complete rows. Keys, labels, state membership, and every variable remain aligned.
- The alphabetically first included state is the reference state.
- At least two states and enough complete observations to estimate the expanded models are required.
- This is a grouped analysis of one cross section, not a multi-period panel fixed-effects estimator.
- The ANOVA is unadjusted; the fixed-effects regression is conditional on the included predictors.
- The reported relationships are descriptive associations. State indicators can absorb omitted geographic differences, but they do not identify which omitted mechanism is responsible.
- Standard errors are conventional OLS standard errors; they are not automatically heteroskedasticity-robust or state-clustered.