Created
August 24, 2015 19:05
-
-
Save felipec/8de112ec3258752245c3 to your computer and use it in GitHub Desktop.
Script para general ingresos correjidos del INEGI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
$hogares = {} | |
open('concentradohogar.csv').each_with_index do |l,i| | |
next if i == 0 | |
data = l.split(',') | |
viv, hog = data[0..1] | |
integ = data[13].tr('"', '').to_i | |
$hogares[[viv, hog]] = [integ, 0] | |
end | |
$exclude = ((50..66).to_a + [9, 16]).map { |e| '"P%03d"' % e } | |
$anual = [8, 9, 15, 16].map { |e| '"P%03d"' % e } | |
open('ingresos.csv').each_with_index do |l,i| | |
next if i == 0 | |
data = l.split(',') | |
viv, hog, _, clave = data[0..3] | |
next if $exclude.include?(clave) | |
ingreso = data[16].to_f | |
raise if ingreso == 0 | |
ingreso /= 2 if $anual.include?(clave) | |
$hogares[[viv, hog]][1] += ingreso | |
end | |
puts '"viv","hog","integ","ingreso","ingreso_pc"' | |
$hogares.each do |(viv,hog),(integ,ingreso)| | |
puts '%s,%s,%d,%f,%f' % [viv, hog, integ, ingreso, ingreso / integ] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment