Announcement

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

  • Averaging across records and excluding certain fields with missing data

    Hi,

    I'm trying to create a new variable within each record that is an average score for 8 variables, labeled Q1, Q2, Q3...etc. within each record. I would like STATA to exclude any fields that have "999" as that's how we coded missing data. Is there a way to code for this exclusion?

    Thanks,
    Nikki

  • #2
    I would like STATA to exclude any fields that have "999" as that's how we coded missing data.
    Well, that's unfortunate, and this problem is just one of the many ways you will come to regret doing that. You should not use numeric codes for missing values when working in Stata. Use Stata's system missing and extended missing values instead. See -help missing- if you are not familiar with these.

    Fortunately, it's easy to convert the data accordingly:

    Code:
    mvdecode varlist, mv(999)
    Then, with real Stata missing values in place, the missings will automatically be ignored by Stata calculations, so the simple and usual:

    Code:
    egen new_variable = rowmean(Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8)
    will do the job.

    Comment


    • #3
      Thanks so much, I'll give this a try.

      Comment

      Working...
      X