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?
Related Posts with Loop results creating random groups are not reproducible
String Cleaning - Possibly automate the taskI wish to retain information on a person's grades which is observed in the variable below. The text …
Merging two datasets - m:mDear Stata Users, Below I have a sample of two datasets: set1 and set2. I need to merge them. The p…
Split variable problemHi I want to divide a variable I have by 2. 01aug2018 will be one variable and the other time. Sampl…
boottest: just as wild, 10X fasterAppendix A.2 of the paper about boottest describes an opportunity to speed up the program's construc…
Combine list options header and sepbyMy question doesn't go far past the title - is there a way to have the list command re-display the h…
Subscribe to:
Post Comments (Atom)
0 Response to Loop results creating random groups are not reproducible
Post a Comment