Announcement

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

  • How can I generating a variable that gives me the average score of postive responses

    Good morning, I have been working on a data bank containing the following dichotomous variables:
    a1 to a18;
    b1 to b4;
    c1 to c6;
    d1 to d3;
    f1 to f11
    A example:
    f11 | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 21 42.00 42.00
    1 | 29 58.00 100.00
    ------------+-----------------------------------
    Total | 50 100.00

    a1 | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 20 40.00 40.00
    1 | 30 60.00 100.00
    ------------+-----------------------------------
    Total | 50 100.00

    b1 | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 13 26.00 26.00
    1 | 37 74.00 100.00
    ------------+-----------------------------------
    Total | 50 100.00

    How can I generating a variable that gives me the average score of postive responses of those variables, like:
    newvar = (58+60+74)/3?
    gen safety= 0
    replace safety= 1 if newvar == 1
    Many thanks in advance!
    William

  • #2
    The safest way to get a mean of means is to calculate a row mean first using egen and then use summarize. Anything else is likely to produce inconsistent results in the face of missing values.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      The safest way to get a mean of means is to calculate a row mean first using egen and then use summarize. Anything else is likely to produce inconsistent results in the face of missing values.
      Thanks for the help.
      I'm new to data analysis with Stata!
      I've tried several ways and failed.
      Could you show how to do it?
      William

      Comment


      • #4
        Code:
        egen rowmean = rowmean(f11 a1 b1)
        su rowmean

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Code:
          egen rowmean = rowmean(f11 a1 b1)
          su rowmean
          Thank you very much!
          Worked perfectly!

          Comment

          Working...
          X