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
Interpreting odds ratio in logit modelsFor my xtlogit model (though Stata shows "Random-effects logistic regression" in the table it produc…
Quarterly data, year-fixed effectHi, This is more of an Econometrics than a Stata question, I hope you don't mind. I am trying to i…
Bivariate Kernal Estimation - optimal bandwidth choiceDear all: I am writing to see if anyone knows a Stata command that helps set the optimal bandwidth …
Comparing the seasonal naive method with Holt-Winters' additive seasonal exp. smoothing method using ts cross-validationHello, Can someone help me with using cross-validation to compare the seasonal naive method with Ho…
Parallel trends assumption in the diff commandI've got a doubt about the diff package. You can check the file about it here. I would like to find…
Subscribe to:
Post Comments (Atom)
0 Response to Loop results creating random groups are not reproducible
Post a Comment