In my data, each participant has obtained a score (SC1) in a game. I want to know for a participant with certain characteristics (female with a score of 10) what their probabilities are of having the highest score in a group of 4. In my case, the participant with id==13 has these characteristics. I'm using forvalues to create 1000 groups and calculate how often the person with id==13 has the highest score. I want to create groups with the id==13 person and 3 others. To ensure that Stata does not take the id==13 person as one of the three others, I assign this person rannum 1 (the highest possible). I have created the following code:

forvalues i=1/1000 {
set seed 37025
generate rannum`i' = runiform()
replace rannum`i' = 1 if id==13 //Assign the highest random number to person id==13 to avoid them having one of the three lowest numbers

sort rannum`i'
generate grp`i' = .
replace grp`i' = 1 in 1/3 //Assign 3 people with the lowest random number to the group
replace grp`i' = 1 if id==13 //Assign person with id==13 to the group

bysort grp`i': egen rnk`i'=rank(SC1) if grp`i'==1, field. //Give every person in the group a performance rank from 1 - 4

generate win`i' = .
replace win`i' = 1 if rnk`i'==1 //Generate a dummy that is 1 if the participant obtained rank 1
}


egen wins = rowtotal(win*) if id==13 //Calculate how often person with id==13 obtained rank 1


The issue that I encounter is that my results are not reproducible. I thought this would be avoided by using the 'set seed' command and sorting the data. Still, every time I run the commands I get a different value for the total amount of wins.

Can someone spot why my results are not reproducible and what I can do about it?