> 2009/7/6 Steven Buck <[email protected]>: >> # 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()]
Yes, but psid.variables() is already a list of variable names, so you could just say varnames = psid.variables() >> 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. psid.dataset() is the list of lists that you need to start. Try this: data = psid.dataset() ages = [ item[0] for item in data ] wages = [ item[1] for item in data ] This way of making a list is called a list comprehension, you can read about them here: http://docs.python.org/tutorial/datastructures.html#list-comprehensions Kent _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
