Announcement

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

  • Computing mean var by age-variable group egen

    I have a database with about 10000 observations and with the following variables: weight, country of residence, gender and age. I want to compare a person’s weight to that of his/her reference group (same country, same gender, and relatively similar age). For each observation I want to compute the mean weight value of those persons with same gender, living in the same country, and with age ranging from 5 years below to 5 years above. I could do something like:
    by country gender, sort: egen=mean(weight)
    but I do not know how to handle the varying age range, which changes for each observation.
    Any help is highly appreciated

  • #2
    Something like this:
    Code:
    rangestat (mean) weight, by(gender country) interval(age -5 5)
    The -rangestat- command is written by Robert Picard, Nick Cox, and Roberto Ferrer. It is available from SSC.

    Code not tested, as you did not provide example data. Beware of typos or other errors.

    I assume that the age variable is measured in years. If, for example, it is measured in months, then 5 years translates to 60 months, and the -interval()- option would have to be changed to -interval(age -60 60)-.

    Comment


    • #3
      Dear Clyde Schechter,
      many thanks for your help. It seems this is exactly what I needed,
      my regards,
      Mariano Rojas

      Comment

      Working...
      X