1

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 pidstands for individual's id and hsizeis a previously created dummy for household size

zlqs1985
  • 509
  • 2
  • 8
  • 25

1 Answers1

0
bysort hhid : egen hhincome = total(cond(head == 1, income, 0) + cond(spouse == 1, income, 0))

or

bysort hhid : egen hhincome = total((head == 1) * income + (spouse == 1) * income)
Nick Cox
  • 35,529
  • 6
  • 31
  • 47
  • Thanks,Nick,it's really a tactful solution. Another a little bit lumpy solution come to me later on – zlqs1985 Dec 29 '14 at 13:52