title: How to generate household income from couple's individual income
body: <p>I need to generate a variable representing household income. I have each individual's income information and have identified the head (<code>head == 1</code>) and spouse (<code>spouse == 1</code>). 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</p>
  
  <pre><code>bys hhid : egen hhincome = total(income)
  </code></pre>
  
  <p>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 <code>egen</code> function or other approach? </p>
  
  <hr>
  
  <p>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 <code>bys hhid:gen hhincome=sum(income) in 1/2 if（pid==2&amp;spouse==1）</code>for married head and <code>bys hhid:gen hhincome=income  if(（pid==2&amp;spouse==.）| hsize==1)</code>for unmarried head or single-member household,where <code>pid</code>stands for individual's id and <code>hsize</code>is a previously created dummy for household size</p>