Announcement

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

  • Assigning the same value for same observation

    Hi, I'm new to stata and I need some help.
    Below I have the data on number of members in a household, total income of that household, incomer per head and id of each person in the same household. I want to match the value of "income per head" same for every person with the same "id" to see their average income, but don't know how to do it. Can anyone help me?
    Thank you very much.
    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	8.0 KB
ID:	1451958


  • #2
    Please read and act on https://www.statalist.org/forums/help#stata (no screenshots, please copy and paste example data from dataex output).

    I suggest one of

    Code:
    bysort newid : egen mean_income = mean(income)
    
    bysort newid : egen mean_income2 = max(income_per_head)
    and study of

    Code:
    help egen

    Comment


    • #3
      Annie:
      you're probably looking for something along the following toy-example:
      Code:
      . set obs 8
      
      . g household_id=1 in 1/4
      
      . replace household_id=2 if household_id==.
      
      . bysort household_id: g id=_n
      
      . bysort household_id: g overall_income=10000 if _n==1
      
      . replace overall_income=0 if overall_income==.
      
      . bysort household_id: egen average_income=mean(overall_income)
      
      . list, sepby( household_id)
      PS: I've come late to the party!
      Last edited by Carlo Lazzaro; 05 Jul 2018, 01:09.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X