Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | gianluca manzi <gianluca.manzi1992@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: Creating a Variable for the average by subgroup for a panel dataset |
Date | Fri, 28 Dec 2012 13:43:05 +0000 |
Dear Statalist, How can I calculate the average of a variable by the subgroup of several other variables? I have a panel dataset of individuals incomes, the state they live in, their ages and genders. I want to calculate the average income for individual i at time period t based on these characteristics and create a variable for this (to use as a "reference income" individual i in time t will compare his income to). So (say) I want to create a variable that will calculate the average income for all women aged 20-30 who live in California; the average income for all men aged 20-30 who live in California; the average income for all women aged 30-40 who live in California; the average income for all men aged 30-40 who live in California; the average income for all women aged 20-30 who live in Texas etc etc. The purpose of this is to create a "reference income" which individual i in period t will compare his/her income to. So if the individual is woman, aged 22, who lives in California, she'll compare her income to the average income of 20-30 year old women who live in California. How do I create this variable? Thank you! * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/