Stata wrapper for the eiExpand R package via rcall. Provides Stata commands for performance analysis, split precinct analysis, and racially polarized voting (RPV) visualization used in voting rights and redistricting litigation.
eiexpand_stata is an extension of eicompare_stata. The two packages form a complete Stata toolkit for voting rights analysis:
| Package | Purpose | Key Functions |
|---|---|---|
| eicompare_stata | Ecological inference — estimate how racial groups voted | ei_good, ei_iter, ei_rxc, ei_compare, ei_plot |
| eiexpand_stata (this package) | Performance & redistricting — evaluate district maps using EI results | eix_performance, eix_perfplot, eix_rpvplot, eix_splitpct |
In a typical voting rights case, the workflow is:
- eicompare_stata: Establish racially polarized voting (RPV) by estimating vote choice by race using ecological inference (Goodman's, iterative EI, RxC Bayesian EI).
- eiexpand_stata: Conduct performance analysis to determine whether minority-preferred candidates would win or lose under adopted or proposed district maps. Handle split precincts when precinct boundaries don't align with district boundaries.
Both packages wrap their corresponding R packages (eiCompare and eiExpand) via rcall, requiring no R programming from the Stata user.
eiexpand_stata provides five commands:
eix_performance— Calculate candidate vote shares within hypothetical or proposed districts (Gingles III / performance analysis)eix_perfplot— Publication-quality visualization of performance analysis resultseix_rpvplot— Publication-quality visualization of RPV estimates (works with eiCompare output)eix_splitpct— Split precinct analysis: adjust vote counts when precincts cross district boundaries using census block VAP dataeix_pctintersect— Calculate percent land area intersection between geometries and a boundary polygon
| Requirement | Minimum Version |
|---|---|
| Stata | 14.0+ |
| R | 4.0+ |
rcall (Stata) |
latest |
eiExpand (R) |
1.0.6+ |
eiCompare (R) |
3.0+ (recommended) |
The spatial commands (eix_splitpct, eix_pctintersect) additionally require the sf R package and its system dependencies (GDAL, GEOS, PROJ).
net install github, from("https://haghish.github.io/github/")
github install haghish/rcallgithub install RPVote/eiexpand_statagithub install RPVote/eicompare_stataeix_setup, install* Load precinct-level election data for a district
use district5_precincts, clear
* Calculate vote shares for each candidate in the district
eix_performance, ///
cands(R_gov D_gov) ///
candnames(McMaster (R), Smith (D)) ///
preferred(White, Black) ///
total(total_gov) ///
contest(Governor) ///
year(2018) ///
jurisdiction(District 5)* Adjust precinct vote counts for split precincts
eix_splitpct, ///
vtdshp(precincts.shp) ///
planshp(district_plan.shp) ///
blockdata(census_blocks.shp) ///
votecols(R_gov D_gov total_gov R_sen D_sen total_sen) ///
verbose* Performance plot (dataset must be performance() output)
eix_perfplot, saving(performance_results.pdf)
* RPV plot (dataset must be rpv_toDF() output)
eix_rpvplot, saving(rpv_analysis.pdf) includeerrorbandSee the full vignette for a detailed walkthrough.
Check and install all R dependencies.
eix_setup [, install]Calculate election outcomes for a set of precincts representing a district.
eix_performance, cands(varlist) candnames(string) preferred(string) ///
total(varname) contest(string) year(string) ///
[election_type(string) map(string) jurisdiction(string) includetotal]Generate a performance analysis bar chart.
eix_perfplot, saving(filename) [title(string) subtitle(string) ///
panelby(string) width(#) height(#)]Generate an RPV analysis plot with optional confidence intervals.
eix_rpvplot, saving(filename) [title(string) panelby(string) ///
contest_sep(string) includeerrorband width(#) height(#)]Perform split precinct analysis using census block VAP data.
eix_splitpct, vtdshp(filepath) planshp(filepath) blockdata(filepath) ///
votecols(string) [lowerthresh(#) upperthresh(#) keeporig verbose saving(filepath)]Calculate percent area intersection between geometries and a boundary.
eix_pctintersect, sfdata(filepath) shape(filepath) [saving(filepath)]Each Stata command:
- Exports data or accepts file paths to spatial data
- Calls the corresponding eiExpand R function via
rcall - Imports results back into Stata (or saves to file)
- Displays formatted output and stores values in
r()
For spatial commands, file paths to shapefiles/GeoPackages are passed directly to R's sf::st_read(), supporting all GDAL-compatible formats.
If you use this package, please cite both eiexpand_stata and the underlying R packages:
Collingwood, L. (2026). eiexpand_stata: Stata wrapper for the eiExpand R package.
https://github.com/RPVote/eiexpand_stata
Carroll, R. & Collingwood, L. (2025). eiExpand: Extensions for eiCompare. R package
version 1.0.6. https://github.com/RPVote/eiExpand
Barreto, M., Collingwood, L., Garcia-Rios, S., & Oskooii, K. (2022). Estimating
candidate support in voting rights cases: Comparing iterative EI and EI-RxC methods.
Sociological Methods & Research, 51(4), 1512-1541.
Loren Collingwood, University of New Mexico Email: lcollingwood@unm.edu
MIT