Skip to content

Instantly share code, notes, and snippets.

@felipec
Created August 24, 2015 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipec/8de112ec3258752245c3 to your computer and use it in GitHub Desktop.
Save felipec/8de112ec3258752245c3 to your computer and use it in GitHub Desktop.
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