Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generate variable which count and sum

    Hello Stata users!
    I think the following is a very easy question, but I'm just a beginner with Stata so I'm trying to learn more and more everyday! :-)
    I have the following variables in my dataset:
    ID_Family N_components Income
    1 3 0
    1 3 1000
    1 3 0
    2 4 10000
    2 4 500
    2 4 0
    2 4 3500
    3 1 20000
    4 2 5000
    4 2 0
    It is a survey with ID of the family interviewed, the number of components of each family, and the income of each person.
    I would like to create a new variable (Fam_income) that for each component reports the family's income (as a sum of the income of each component)
    Just like that:
    ID_Family N_components Income Fam_income
    1 3 0 1000
    1 3 1000 1000
    1 3 0 1000
    2 4 10000 14000
    2 4 500 14000
    2 4 0 14000
    2 4 3500 14000
    3 1 20000 20000
    4 2 5000 5000
    4 2 0 5000
    Someone can help me, please?
    Thanks in advance!

  • #2
    student90: The request to you voiced by Carlo Lazzaro on 19 January 2015 that you use a full real name still stands. Please see

    http://www.statalist.org/forums/help#realnames

    http://www.statalist.org/forums/help#adviceextras Section 3

    Code:
    * read the help first
    help egen
    
    bysort ID_Family: egen Fam_income = total(Income)

    Comment

    Working...
    X