Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eiexpand_stata

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.

Relationship to eiCompare

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:

  1. eicompare_stata: Establish racially polarized voting (RPV) by estimating vote choice by race using ecological inference (Goodman's, iterative EI, RxC Bayesian EI).
  2. 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.

Overview

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 results
  • eix_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 data
  • eix_pctintersect — Calculate percent land area intersection between geometries and a boundary polygon

Requirements

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).

Installation

Step 1: Install rcall

net install github, from("https://haghish.github.io/github/")
github install haghish/rcall

Step 2: Install eiexpand_stata

github install RPVote/eiexpand_stata

Step 3: Install the companion eicompare_stata (recommended)

github install RPVote/eicompare_stata

Step 4: Verify setup and install R dependencies

eix_setup, install

Quick Start

Performance analysis

* 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)

Split precinct analysis

* 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

Visualization

* 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) includeerrorband

See the full vignette for a detailed walkthrough.

Commands

eix_setup

Check and install all R dependencies.

eix_setup [, install]

eix_performance

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]

eix_perfplot

Generate a performance analysis bar chart.

eix_perfplot, saving(filename) [title(string) subtitle(string) ///
    panelby(string) width(#) height(#)]

eix_rpvplot

Generate an RPV analysis plot with optional confidence intervals.

eix_rpvplot, saving(filename) [title(string) panelby(string) ///
    contest_sep(string) includeerrorband width(#) height(#)]

eix_splitpct

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)]

eix_pctintersect

Calculate percent area intersection between geometries and a boundary.

eix_pctintersect, sfdata(filepath) shape(filepath) [saving(filepath)]

How It Works

Each Stata command:

  1. Exports data or accepts file paths to spatial data
  2. Calls the corresponding eiExpand R function via rcall
  3. Imports results back into Stata (or saves to file)
  4. 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.

Citation

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.

Author

Loren Collingwood, University of New Mexico Email: lcollingwood@unm.edu

License

MIT

About

Stata wrapper for the eiExpand R package via rcall. Performance analysis, split precinct analysis, and RPV visualization for voting rights litigation. Extension of eicompare_stata.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages