Stata wrapper for the eiCompare R package via rcall. Provides Stata commands for ecological inference (EI) analysis commonly used in racially polarized voting (RPV) litigation and research.
eicompare_stata brings the full power of the eiCompare R package to Stata users without requiring any R programming. It supports three standard EI methods:
- Goodman's ecological regression — fast, linear, can produce out-of-bounds estimates
- Iterative EI (King's method) — bounded 2×2 EI with uncertainty measures
- RxC Bayesian EI — joint multi-candidate, multi-group MCMC estimation
The package also provides commands for side-by-side method comparison and visualization.
| Requirement | Minimum Version |
|---|---|
| Stata | 14.0+ |
| R | 4.0+ |
rcall (Stata) |
latest |
eiCompare (R) |
3.0.6+ |
github install haghish/rcallIf you don't have the github command:
net install github, from("https://haghish.github.io/github/")
github install haghish/rcallgithub install RPVote/eicompare_stataOr from a local copy:
net install eicompare_stata, from("/path/to/eicompare_stata")ei_setup, installThis checks that R is accessible, verifies rcall works, and installs the eiCompare, ei, and eiPack R packages if they are missing.
| Command | Description |
|---|---|
ei_setup |
Check and install dependencies |
ei_good |
Goodman's ecological regression |
ei_iter |
Iterative EI (King's method) |
ei_rxc |
RxC Bayesian EI (MCMC) |
ei_compare |
Compare results across methods |
ei_plot |
Visualize EI results |
* Verify dependencies
ei_setup
* Load your election data (precinct-level with vote shares and demographic shares)
use my_election_data, clear
* Run Goodman's regression
ei_good cand_a cand_b, races(pct_white pct_black pct_hisp) totals(total_votes)
* Run iterative EI
ei_iter cand_a cand_b, races(pct_white pct_black pct_hisp) totals(total_votes) seed(12345)
* Run RxC Bayesian EI
ei_rxc cand_a cand_b, races(pct_white pct_black pct_hisp) totals(total_votes) seed(12345)
* Compare all three methods
ei_compare cand_a cand_b, races(pct_white pct_black pct_hisp) totals(total_votes) seed(12345)
* Generate a comparison plot
ei_plot cand_a cand_b, races(pct_white pct_black pct_hisp) totals(total_votes) ///
saving(ei_results.pdf) seed(12345)See the full vignette for a detailed walkthrough with real-world guidance.
The package includes a comprehensive vignette covering:
- Data preparation and variable requirements
- Running each EI method with explanation of parameters
- Interpreting results
- Comparing methods for RPV analysis
- Visualization options
- Practical tips for Voting Rights Act Section 2 litigation
Read the full vignette: eicompare_stata_vignette.md
Each Stata command:
- Exports the current dataset to a temporary CSV
- Calls the corresponding eiCompare R function via
rcall - Imports the results back into Stata
- Displays a formatted results table
- Stores key values in
r()for programmatic use
No R coding is required — the .ado files handle all R code generation internally.
Your dataset should contain precinct-level data with:
- Candidate variables: Vote shares as proportions (0 to 1) for each candidate. Must sum to 1 within each precinct.
- Race variables: Demographic group shares as proportions (0 to 1). Must sum to 1 within each precinct.
- Totals variable: Total number of votes (or voting-age population) per precinct.
If you use this package, please cite both eicompare_stata and the underlying R package:
Collingwood, L. (2026). eicompare_stata: Stata wrapper for the eiCompare R package.
https://github.com/RPVote/eicompare_stata
Collingwood, L., Oskooii, K., Garcia, S., & Barreto, M. (2020). eiCompare: Comparing
ecological inference estimates across EI and EI:RC. R package.
https://github.com/RPVote/eiCompare
Loren Collingwood, University of New Mexico Email: lcollingwood@unm.edu
MIT