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
Panel data - Following the death of a participant, how to remove all following observations for themHi everyone! I currently am cleaning a very big dataset (52 variables, 82284 observations) for long…
Deciding on best matching algorithm with kmatchDear statalisters, Based on the paper of King and Nielson (2016) on the comparative analysis of mat…
problems creating a graph, diagram, etc.Hello, Creating a graph, a diagram etc. doesn't work in my Stata program. The small box, that usuall…
Choice model margins problem: margins after cmclogit producing _outcome#altDear all, I am using data from a choice experiment with an unbalanced panel of 2-3 alternatives per…
mycolours package available on SSCThanks as always to Kit Baum who maintains SSC, a new package mycolours is available from SSC. The p…
Subscribe to:
Post Comments (Atom)
0 Response to Loop results creating random groups are not reproducible
Post a Comment