Announcement

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

  • How to calculate average value of a variable at each cluster

    Hello,
    have a look at the below data

    Code:
    360002  0
    360020  7
    360024  7
    360037  0
    360041  0
    360041  0
    360049  0
    360049 10
    360063  0
    360063  0
    360063  0
    360063  2
    360063  0
    360066  0
    360066  6
    360066  0
    360072  0
    360081  6
    360095  3
    360110  7
    360111  0
    360111  0
    360111  0
    360111  0
    360116  0
    360116  0
    360117  0
    360119 12
    360125  0
    360125  0
    360129  0
    360134  4
    360135  7
    360140  0
    360140  0
    360140  0
    360142  0
    360142  0
    360142  0
    360142  0
    360142  0
    360153  0
    360155  0
    360155  0
    360164  0
    360165  7
    360165  7
    360168  0
    360187  3
    360187  3
    360192  0
    360196  7
    360196  7
    360208  4
    360208  1
    360209  0
    360209  0
    360215  0
    360215  0
    360215  0
    360231  1
    360231  0
    360231  0
    360258  0
    360258  0
    360261  0
    360261  0
    360261  1
    360261  0
    360261  0
    360261  0
    360261  0
    360269  0
    360269  0
    360269  5
    360285  8
    360288 12
    360288 12
    360288 12
    360288  7
    360290  0
    360290 12
    360290  0
    360292  0
    360293  0
    360293  0
    360293  0
    360297  5
    360309  0
    360309  0
    360315 10
    360315  0
    360315 10
    360320  0
    360321  0
    360321  0
    360322  9
    360322  9
    360322  0
    360330  0
    here the first column is showing the cluster number and second column is 'years of schooling'
    I want to calculate average years of schooling at each cluster, and make a third variable.
    Is there any command in STATA through which i can do this

    Thanks and Regard

  • #2
    That's just

    Code:
    egen wanted = mean(schooling), by(cluster)
    where naturally you should use the, variable names you have but didn't show us.

    Code:
    help egen
    https://www.statalist.org/forums/help#spelling

    Comment


    • #3
      Endless Thanks to you Sir

      Comment

      Working...
      X