Good morning,

Would appreciate some code that generates in the wanted var, the average for the master var, by its rank (tfmaster_rank)
In the example the average of the top 4 ranked is 103.25. In the larger dataset there is a grouping variable 'id'
Thank you.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str22 id int master byte tfmaster_rank float wanted
"Star Of Emaraaty44427"  106  1 103.25
"Rising Star44427"       104  2 103.25
"Agincourt44427"         103  3 103.25
"Spirit Of Bermuda44427" 100  4 103.25
"Sweet Enough44427"       96  5 103.25
"Thunder Beauty44427"     95  6 103.25
"Improvised44427"         94  7 103.25
"Setarhe44427"            90  8 103.25
"Arabian Romance44427"    90  8 103.25
"Separate44427"           90  8 103.25
"Coul Queen44427"         86 11 103.25
"Lottie Marie44427"       82 12 103.25
end