Announcement

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

  • Calculating mean from a set of variables


    This is how the data set looks right now. I want to calculate a new variable mean/avg BP for each patient over the period of followup. Mean bp: (sbp3m + sbp6m +..../n)
    But there are missing observations like a lot for some pts. What is the best way to do that?
    Please please do reply I am stuck here!!

    clear
    input long mrn07 int(sbp3m sbp6m)
    1558 . .
    6394 146 112
    22243 . .
    30490 130 .
    33638 . .
    44044 . .
    52431 . .
    56161 142 .
    71354 120 .
    82315 . 149
    89298 . .
    89790 . .
    90846 . 179
    94139 . .
    136683 . 90
    141293 . .
    143430 142 146
    146924 . .
    167432 . .
    168955 . .
    322305 . .
    322870 . .
    340177 . .
    347074 . .
    357372 121 .
    408326 . .
    409279 . .
    413870 120 129
    426366 . 104
    434822 140 136
    440228 . 140
    444144 . .
    449069 118 102
    451379 . .
    457911 . .
    459979 135 114
    461106 118 .
    490384 148 .
    497844 120 136

  • #2
    Ushma:
    first, you should decide how to handle missing values.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      I dont want to include missing values in the mean. I have data from 0 to 60 months at 3 months interval so 21 values for each pts
      For example if for a particular ID I have 6 missing values , then the mean should be the sum of rest 15 values/ n-6
      Is there a way I can do this in STATA?

      Thank you so much!! I am still very new and learning STATA as I go

      Comment


      • #4
        Ushma:
        excluding missing values by listwise deletion (as Stata does by default for technical reasons concerning matrix algebra) without diagnosing the mechanism underlying their missingness may severely bias your results.
        That said, you may want to consider:
        Code:
        . egen wanted=rowmean( sbp3m sbp6m)
        (21 missing values generated)
        
        . list in 1/10
        
             +--------------------------------+
             | mrn07   sbp3m   sbp6m   wanted |
             |--------------------------------|
          1. |  1558       .       .        . |
          2. |  6394     146     112      129 |
          3. | 22243       .       .        . |
          4. | 30490     130       .      130 |
          5. | 33638       .       .        . |
             |--------------------------------|
          6. | 44044       .       .        . |
          7. | 52431       .       .        . |
          8. | 56161     142       .      142 |
          9. | 71354     120       .      120 |
         10. | 82315       .     149      149 |
             +--------------------------------+
        
        .
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Hi I am getting this error. I ran the exact code you suggested.

          egen wanted=rowmean( sbp0m sbp3m sbp6m sbp9m sbp12m sbp15m sbp18m sbp21m sbp24m sbp27m sbp30m sb
          > p33m sbp36m sbp39m sbp42m sbp45m sbp48m sbp51m sbp54m sbp57m sbp60m )
          type mismatch

          Please help!!

          Comment


          • #6
            Ushma:
            are you sute that all your -sbp*- variables are in numeric format?
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              After that I tried again and one of the variables was a string variable I converted it to numeric and it worked!!
              Thank you so much

              Comment

              Working...
              X