Skip to content

Instantly share code, notes, and snippets.

Bonus example:
The IPUMS SDA query interface allows you to collapse variables into broader categories. I do this often with occupations -- individual occupations are usually too small to carry a meaningful sample size, but if you look at the occupational hierarchy in the docs, you can see how you might tile up individual occupations into broader but still meaningful categories.
So try this.
1) Pick any sample to query
2) put sex as your column
@gebelo
gebelo / zoomer!
Created March 14, 2016 17:57
leaflet zoomer problem
The correct 'link':
<div class='map-navigation' data-zoom='12' data-position='<%=d.tractlat%>,<%=d.tractlon%>'>Zoom</div>
The 'link' that zoomed but then reloaded page:
<div class='map-navigation'><a href='' data-zoom='12' data-position='<%=d.tractlat%>,<%=d.tractlon%>'>Zoom</a></div>
The zoomer function:
document.querySelector('.map-navigation').onclick = function(abc) {
var pos = abc.target.getAttribute('data-position');
var zoom = abc.target.getAttribute('data-zoom');
@gebelo
gebelo / gist:5cc47579a2259d7e0d9953ddd3b0b2ea
Last active May 10, 2016 11:33
US Native American Population
2010-2014, ACS 5-year sample
Source: IPUMS.org
Nativer American Alone, by Tribal Identification
302: Apache 70,940
303: Blackfoot 28,256
304: Cherokee 279,721
305: Cheyenne 14,386
306: Chickasaw 23,110
307: Chippewa 114,423
@gebelo
gebelo / gist:4aee93ba6d622b42ced6953881310b14
Created June 7, 2016 18:28
Ugly but effective MySQL conversion of m/d/y string into yyyy-mm-dd date
SELECT dob, SUBSTRING_INDEX( `dob` , '/', 1 ) AS mo,
SUBSTRING_INDEX(SUBSTRING_INDEX( `dob` , '/', 2 ),'/',-1) AS dy,
SUBSTRING_INDEX(SUBSTRING_INDEX( `dob` , '/', 3 ),'/',-1) AS yr,
CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX( `dob` , '/', 3 ),'/',-1),"-",SUBSTRING_INDEX( `dob` , '/', 1 ),"-",SUBSTRING_INDEX(SUBSTRING_INDEX( `dob` , '/', 2 ),'/',-1)) AS dt
FROM table
"dob" "mo" "dy" "yr" "dt"
"7/19/1970" "7" "19" "1970" "1970-7-19"
from matplotlib.colors import LinearSegmentedColormap
bins = [0,1]
# Maps values to a bin.
# The mapped values must start at 0 and end at 1.
def bin_mapping(x):
for idx, bound in enumerate(bins):
if x < bound:
return idx / (len(bins) - 1.0)
@gebelo
gebelo / hudpublic.csv
Last active June 25, 2019 21:01
Nursing Home List
These 74 nursing homes with HUD-backed mortgages appeared recently a Congressional list of facilities that have “serious deficiencies.”
We can't make this file beautiful and searchable because it's too large.
geoid,pop_density,paved_density,tract_type
01001020100,3,3,3) OUTER RING
01001020200,5,5,3) OUTER RING
01001020300,5,4,3) OUTER RING
01001020400,5,4,3) OUTER RING
01001020500,6,6,2) INNER RING
01001020600,4,4,3) OUTER RING
01001020700,3,3,3) OUTER RING
01001020801,2,2,4) RURAL
01001020802,2,2,4) RURAL
@gebelo
gebelo / nytcounties.csv
Created October 29, 2019 16:41
this is population distribution by county based on our density estimates... pop is tract level aggregated, from 2013-2017 ACS
statename countyfips countyname urban inner outer rural total urban_pct isuburb_pct osuburb_pct
al01 01001 Autauga County 0 9965 18709 26362 55036 0 0.18106330401918744 0.3399411294425467
al01 01003 Baldwin County 0 0 149067 54293 203360 0 0 0.7330202596380803
al01 01005 Barbour County 0 0 6045 20156 26201 0 0 0.23071638487080645
al01 01007 Bibb County 0 0 0 22580 22580 0 0 0
al01 01009 Blount County 0 0 0 57667 57667 0 0 0
al01 01011 Bullock County 0 0 0 10478 10478 0 0 0
al01 01013 Butler County 0 0 4368 15758 20126 0 0 0.21703269402762596
al01 01015 Calhoun County 1197 3854 82703 27773 115527 0.010361214261601184 0.03336016688739429 0.7158759424203865
al01 01017 Chambers County 0 0 12473 21422 33895 0 0 0.36798937896444905
@gebelo
gebelo / gist:94dbc276882846175d74b0b1360d53d1
Created April 18, 2020 15:14
These are industry and occupation codes used in a New York Times story about gender dynamics of the coronavirus pandemic "essential" workforce, https://www.nytimes.com/2020/04/18/us/coronavirus-women-essential-workers.html
"isHealth=ifelse((IND>=7970 & IND<=8290) | (OCC>=3000 & OCC<=3550),1,0),
isHealth=ifelse(OCC==3250 |OCC==3424, 0, isHealth)," "Offices of physicians
Offices of dentists
Offices of chiropractors
Offices of optometrists
Offices of other health practitioners
Outpatient care centers
Home health care services
Other health care services
General medical and surgical hospitals, and specialty (except psychiatric and substance abuse) hospitals
@gebelo
gebelo / top40health
Created April 19, 2020 19:20
Breakdown of Health care occupations by gender, race, ethnicity and nativity, via our New York Times story https://www.nytimes.com/2020/04/18/us/coronavirus-women-essential-workers.html
Occupation,workers,Female,NonWhite,Black,Hispanic,Asian,ForeignBorn-Citizen,ForeignBorn-NonCitizen
Registered nurses,"3,171,358",89%,29%,11%,7%,9%,12%,3%
Nursing assistants,"1,369,106",89%,57%,34%,14%,5%,14%,9%
Physicians,"882,804",38%,35%,5%,6%,21%,21%,7%
Licensed practical and licensed vocational nurses,"863,026",87%,45%,26%,12%,5%,10%,4%
Personal care aides,"720,868",84%,56%,27%,18%,8%,12%,11%
Medical and health services managers,"631,539",72%,30%,12%,10%,5%,9%,3%
Medical assistants,"497,345",92%,49%,13%,29%,4%,10%,5%
"Secretaries and administrative assistants, except legal, medical, and executive","470,105",96%,30%,11%,13%,4%,7%,3%
Receptionists and information clerks,"459,777",95%,39%,11%,21%,4%,6%,4%