I need to generate a variable representing household income. I have each individual's income information and have identified the head (head == 1
) and spouse (spouse == 1
). Now I decide to define the household income as head's income plus their spouse's income if the head is married or the head's income if unmarried. In this case, I cannot simply use some command like
bys hhid : egen hhincome = total(income)
because there may be other members in the household who receiveincome, such as adult children living with their parents. So how can I achieve my goal, either using an egen
function or other approach?
Thanks,Nick,it's really a tactful solution. Another a little bit lumpy solution come to my mind later on : Given I have used bysort prefix to generate the two dummy,head and spouse, the head and his/her spouse should appear as the first two members in each household group,then I can write something like bys hhid:gen hhincome=sum(income) in 1/2 if(pid==2&spouse==1)
for married head and bys hhid:gen hhincome=income if((pid==2&spouse==.)| hsize==1)
for unmarried head or single-member household,where pid
stands for individual's id and hsize
is a previously created dummy for household size