Dear Statalisters,
I am having a dataset with individuals belonging to different groups and I am running a simulation with many repetitions. Per repetition, one individual is randomly drawn from each group using the sample command, e.g.
Since sample relies on sorting the data (which makes the code run rather slowly), I would like to use the user-written command randomtag (from SSC) that tags the same observations that sample would select but does not sort the observations.
My problem is that randomtag does not have a by() option, so I can't use it to sample one individual per group. Does anyone has an idea how to accomplish this with randomtag or with another workaround
If anyone has any ideas, please let me know, thank you in advance!
Ali
I am having a dataset with individuals belonging to different groups and I am running a simulation with many repetitions. Per repetition, one individual is randomly drawn from each group using the sample command, e.g.
Code:
*A toy example clear *Generate 100 different groups set obs 100 generate long group=_n *Generate 1000 indivudals per group expand 1000 bysort group: gen individual=_n *Sample 1 individual per group by group: sample 1, count
My problem is that randomtag does not have a by() option, so I can't use it to sample one individual per group. Does anyone has an idea how to accomplish this with randomtag or with another workaround
If anyone has any ideas, please let me know, thank you in advance!
Ali
Comment