Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Script para general ingresos correjidos del INEGI
#!/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