Announcement

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

  • Calculating means

    Dear Stata experts,

    I need help creating variables with the mean run values of the 'X_A3', 'Y_A3', and 'S_A3' per SampleID. Each blood sample (variable SampleID) is analyzed once, twice or three times. The number of times each sample is analyzed is found in the variable Run. The results from each analysis is presented in 'X_A3', 'Y_A3', and 'S_A3' parameters. I want to calculate the mean of the run results for each sample, and the new 'X_A3', 'Y_A3', and 'S_A3' shall have only one value (the mean) per sample. This is an example of the data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex clear input long SampleID byte Run double(X_A3 Y_A3) int S_A3 45635001 1 4.95 5.20999999999999 142 45635001 2 4.96999999999999 5.11 142 45635002 1 4.49 5 148 45635002 2 4.44 4.99 147 45635003 1 9.31 5.12999999999999 172 45635004 1 9.58 5.15 169 45635004 2 7.13999999999999 4.45 135 45635004 3 7.07 4.4 135 45635005 1 4.21999999999999 4.79 147 45635005 2 4.19 4.82 147 45635006 1 6.45999999999999 4.58999999999999 137 45635006 2 6.53 4.54999999999999 138 45635007 1 4.5 4.79 144 45635007 2 4.50999999999999 4.75999999999999 145 45635008 1 5.54999999999999 4.23 135 45635009 1 5.16999999999999 4.9 152 45635009 2 5.17999999999999 4.87999999999999 153 45635009 3 5.2 4.57 155 45635010 1 5.28 4.54 133 45635011 1 6.16 4.82 135 45635011 2 6.05999999999999 4.74 133 45635012 1 4.74 4.83 149 45635012 2 4.79999999999999 4.76999999999999 151 45635013 1 4.71999999999999 4.95 143 45635013 2 4.7 4.95 143 45635014 1 3.47 4.42999999999999 153 45635014 2 3.47999999999999 4.4 152 45635015 1 5.26999999999999 5.33999999999999 153 45635015 2 5.29 5.28 153 45635016 1 8.38 4.20999999999999 104 45635016 2 8.36999999999999 4.20999999999999 104 45635017 1 7.91999999999999 3.79999999999999 91 45635017 2 7.57 3.75999999999999 91 45635018 1 7.12999999999999 5.67999999999999 172 45635018 2 7.2 5.65 172 end
    I appreciate your help with the appropriate command(s).

    Thank you in advance.
    Best,
    Amanda
Working...
X