Coder Social home page Coder Social logo

ipums-helper's Introduction

Purpose:
To provide a simple function that maps the raw IPUMS data extract to the variable values it represents.

For example, the first few lines of an IPUMS data file might look like the following:

2008010000008200082000
2008010000002300066000
2008010000008800070021
2008010000006600070000
2008010000006600069000

Here, each line represents a single survey respondent. The first four characters of the line are the YEAR variable, the next two are the STATEFIP variable, the next 10 are the PERWT, etc.

The row_generator() function uses the IPUMS data file and the DDI xml file that accompanies it to automatically parse each line of the data file into a dictionary with each key representing the variable value.

Usage:

Step 1: Download the IPUMS dat file (ie, "usa_00001.dat") and the corresponding DDI file (for example, "usa_00001.xml") from the IPUMS website.
Step 2: Import the row_generator function from the ipums_lib function
Step 3: Create a row_generator, supplying the paths to the IPUMS dat file and the corresponding DDI file.

Example Usage:
>>> from ipums_lib import row_generator
>>>
>>> rows = row_generator(datapath = "usa_00001.dat", ddipath = "usa_00001.xml")
>>> for row in rows:
>>>     print row

{u'STATEFIP': '01', u'PERWT': '00000082.00', u'AGE': '082', u'MIGPLAC1': '000', u'YEAR': '2008'}
{u'STATEFIP': '01', u'PERWT': '00000023.00', u'AGE': '066', u'MIGPLAC1': '000', u'YEAR': '2008'}
{u'STATEFIP': '01', u'PERWT': '00000088.00', u'AGE': '070', u'MIGPLAC1': '021', u'YEAR': '2008'}
{u'STATEFIP': '01', u'PERWT': '00000066.00', u'AGE': '070', u'MIGPLAC1': '000', u'YEAR': '2008'}
{u'STATEFIP': '01', u'PERWT': '00000066.00', u'AGE': '069', u'MIGPLAC1': '000', u'YEAR': '2008'}

ipums-helper's People

Contributors

ameasure avatar timdumol avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.