[Tutor] append question

Rich Lovely roadierich at googlemail.com
Mon Jul 6 06:22:50 CEST 2009


2009/7/6 Steven Buck <buckstec at gmail.com>:
> Thanks for the previous responses.  This isn't homework--I'm beyond
> coursework, although I am a newbie to Python (and I've never had to do much
> real programming since I've just used Stata for econometric analysis).  I'm
> testing Python as a more powerful alternative to Stata.
>
> I've learned from the responses I received, although now see my problem
> differently.  The data structure I have uses a dictionary and know now
> that the append command doesn't work.  Having said that, perhaps my
> variables of interest have already been created--perhaps I just don't know
> how to identify them.  I've been using some borrowed code to get me started;
> my modified version is below:
>
>
> import sys
>
> # The modules below help me get a .dta file into Python.
> # Although I'm not sure what form they take; I suppose a list of lists???
> from StataTools import Reader
> from StataTypes import MissingValue
>
> # I call my data set the psid (Panel Study of Income Dynamics)
> # In Stata this would look like and NXK matrix (N observations and K
> variables)
> psid=Reader(file('data3.dta'))
>
> # I gather this next just creates a list of the variable names.
> varnames=[x.name for x in psid.variables()]
>
> # It's not clear what these next two lines gain me.
> labels=psid.file_headers()['vlblist']
> Labels=dict(zip(varnames,labels))
>
>
>  From here, I'd like Python to identify the Nx1 vectors (or n-tuples) that
> correspond to the varnames list defined above.  I can't seem grab the
> vectors representing age, wage, etc..  I've tried things like
> age, psid['age'], psid.age.  My last email was an attempt to create the
> vectors myself, although the Reader module puts the data in a dictionary
> structure so the append command I was trying to use doesn't work.
>
> Hopefully once I learn to create and call on my own vectors and matrices
> I'll be better off--I'm comfortable working with these in MATLAB and Stata.
>
> Bottom line:  Given the above data I've imported/extracted from Stata .dta
> file, how do I create an Nx1 vector  which I call 'age'?
>
> Thanks for your patience with this newbie.
> Steve

Sorry about suggesting this was homework... I noticed the word
University, but not the line above it saying "PhD student"...

If you're new to python, the standard path we recommend is to take an
online tutorial.

Dive into Python (http://www.diveintopython.org/) has been recommended
for people with some programming experience, and Think Python for
those without, although I'm sure that if you ask 10 members of this
list, you'll get 20 different suggestions.  Real veterans get pointed
at the standard libraries, which are extremly well commented in the
most part.  I personally learned from the tutorial in the python
documentation, but it does leave a fair bit of the thought processes
involved in programming out.

See what I mean?  One person, three recomendations.

-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com


More information about the Tutor mailing list