# making the amazing apportionment machine

I was born in Northern Colorado and now live just outside the District of Columbia. I can attest from personal experience that these two places do not share much. Except, that is, for their desire to become states.1

I was curious what would happen if both became states as a modern-day [Missouri Compromise]. I wrote the following script to make the Amazing Apportionment Machine to reapportion seats and looked at two scenarios: the current distribution of congressional districts and the distribution if "Northern Colorado" and the "State of Columbia" were added as states.

The code has some useful tricks for general purpose in it. First, it defines a program (called apportionseats) since the exact same code would be used to apportion seats under a) the current scenario, which is useful to check my work, and b) a new scenario with Northern Colorado and DC included as states. Then, it loads a .csv file (available here) with state names and abbreviations. I save this as a "temporary file," which is a useful trick that I have learned to use when merging two datasets that both need some data management. I then merged this temporary file with a file I downloaded from Social Explorer containing population data for each state (file available here). The first non-name line contains a variable label (see my previous post for a way to label variables using this data format). I then create the apportionment under the current scenario by dropping DC and running the apportionment program.

After this, I reload the temporary data (which adds DC back into the dataset). I create a new state (North Colorado, postal abbreviation "CN" since "NC" was taken by North Carolina). I then cycle through the population of Northern Colorado counties by hacking a hash map that adds the population (second word in each local macro) to the state of Northern Colorado and subtracts it from Colorado's population. I then run the reapportionment program again and figure out what would change. You can find my summary on Scatterplot.

qui cap program drop apportionseats
program define apportionseats
// Syntax is:
// . apportionseats N
// where N is the number of seats to be apportioned
local seats 1'

gen reps = 1
gen A = pop2010/sqrt(reps*(reps+1))
count
local next_rep = r(N)'+1

gsort -A
while next_rep'<=seats' {
qui replace reps = reps + 1 in 1
qui replace A=pop2010/sqrt(reps*(reps+1))
gsort -A
local ++next_rep'
}
end

clear
cd ~/blog/reapportionment/

// Merge states with abbreviations and full names to population data obtained from Social Explorer
insheet using states.csv, names
sort state
tempfile states
save states'
insheet using state_populations.txt, clear names
drop in 1
destring totalpopulation2010, replace
rename qualifyingname state
rename totalpopulation2010 pop2010
keep state pop2010
merge 1:1 state using states'
save states', replace

// Apportion seats using current states
drop if abbreviation=="DC"
apportionseats 435
rename reps current_reps
drop A
gen propcurr = pop2010/current_reps

// Re-merge data to get DC back and to create scenario with North Colorado and DC as states
merge 1:1 state using states', gen(_m2)

// First word of each local is county name, second is population in 2010
local noco1 weld 252825
local noco2 morgan 28159
local noco3 logan 22709
local noco4 sedgwick 2379
local noco5 phillips 4442
local noco6 washington 4814
local noco7 yuma 10043
local noco8 kit_carson 8270
local noco9 cheyenne 1836

set obs 52
replace state="Northern Colorado" if state==""
replace abbreviation="CN" if state=="Northern Colorado"
replace pop2010=0 if abbreviation=="CN"

// Add county populations to North Colorado and substract from Colorado population
local i = 1
while "nocoi''"!="" {
local county_pop : word 2 of nocoi''
replace pop2010 = pop2010 + county_pop' if abbreviation=="CN"
replace pop2010 = pop2010 - county_pop' if abbreviation=="CO"
local ++i'
}

apportionseats 435

// Generate values measuring the proportional representation after adding new states
gen propnew  = pop2010/reps
gen propdiff = propnew - propcurr

// Report results
sort state
list state current_reps reps propcurr propnew propdiff


It would be possible to examine other scenarios as well -- population loss/growth or changing the number of seats in Congress (as Congress has the prerogative to do).

1. Technically, where I was born is happy being part of Colorado).

#### Pingbacks

Pingbacks are open.