Hello,
Would appreciate some assistance on a calculation for 2 new variables please.
By the group var, I need to get the average value of the top half ranked and bottom half ranked of the value var, both returned in 2 new vars in columns 4 and 5.
The problem I'm having is when there is an odd number of cases in the group such as in this example, which has 11.
I would like to add the values for the top 5 ranked and half the value of the 6th ranked (as it is in the middle) eg. 23+45+56+2+4+46.5 (half the value of 93 (rank 6), then get the average of this number by dividing by half the cases 11 / 2 = 5.5, therefore giving an average top half value of 32.09, returned in a new var in the column next door. Same calculation applied to the bottom half eg. (75+36+12+52+19+46.5) / 5.5 = 43.73
Thanks,
Hans
Would appreciate some assistance on a calculation for 2 new variables please.
By the group var, I need to get the average value of the top half ranked and bottom half ranked of the value var, both returned in 2 new vars in columns 4 and 5.
The problem I'm having is when there is an odd number of cases in the group such as in this example, which has 11.
I would like to add the values for the top 5 ranked and half the value of the 6th ranked (as it is in the middle) eg. 23+45+56+2+4+46.5 (half the value of 93 (rank 6), then get the average of this number by dividing by half the cases 11 / 2 = 5.5, therefore giving an average top half value of 32.09, returned in a new var in the column next door. Same calculation applied to the bottom half eg. (75+36+12+52+19+46.5) / 5.5 = 43.73
Thanks,
Hans
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str6 groupvar byte(rank value) float(average_of_top_half_rank average_of_bottom_half_rank) "Friday" 1 23 32.09 43.73 "Friday" 2 45 32.09 43.73 "Friday" 3 56 32.09 43.73 "Friday" 4 2 32.09 43.73 "Friday" 5 4 32.09 43.73 "Friday" 6 93 32.09 43.73 "Friday" 7 75 32.09 43.73 "Friday" 8 36 32.09 43.73 "Friday" 9 12 32.09 43.73 "Friday" 10 52 32.09 43.73 "Friday" 11 19 32.09 43.73 end
Comment