Hi Stata Listers,
I drew a random sample from my dataset recently, using set seed first, but when I re-run the commands, a different sample is drawn.
I am wondering why I'm not getting the same subset of my data each time.
Here is a snippet of the code I'm using in Stata 13:
*Sort the unique identifier
sort ID
*Set the seed using a random number
set seed 66848309
*Sample 60 records from each group, defined by the variable "group"
bysort group: sample 60 if group==1 | group==2 | group==3, count
I've read that this may be due to the sort not being stable, but I haven't been able to use the stable option with bysort. Any ideas?
Thanks for reading.
I drew a random sample from my dataset recently, using set seed first, but when I re-run the commands, a different sample is drawn.
I am wondering why I'm not getting the same subset of my data each time.
Here is a snippet of the code I'm using in Stata 13:
*Sort the unique identifier
sort ID
*Set the seed using a random number
set seed 66848309
*Sample 60 records from each group, defined by the variable "group"
bysort group: sample 60 if group==1 | group==2 | group==3, count
I've read that this may be due to the sort not being stable, but I haven't been able to use the stable option with bysort. Any ideas?
Thanks for reading.
Comment