Hi Statalisters! I have the following problem.
I have N individuals and I would like to assign to them n random numbers. Since n<N what I need to do (I guess) is to generate n random groups of random size. I did the following:
generate rannum = uniform()
egen randomnumber = cut(rannum), group(n)
and it would work but it creates groups of equal size that is not what I need.
I also tried this:
gen randomnumber = runiformint(1,n)
which also would work but does not assign all the numbers between 1 and n (let us say, almost all for some reason I don't get), and again is not what I need.
Just to be clear, suppose N=10 and n=4, I'd like to have something like:
individuals randomnumber
1 2
2 3
3 3
4 1
5 4
6 1
7 3
8 4
9 2
10 1
Where randomnumber is randomly assigned to individuals.
Thanks for any help!
Related Posts with random numbers to groups of random size
Mothers literacyHello, I wish to generate mother's matriculation literacy dummy (edu_matri) and illterate dummy (ill…
IV RegressionHello everyone. May I please have some assistance on what command I should use for my IV regression?…
Trouble with metadta for diagnostic test accuracy systematic reviewHello, im relatively new to stata so please forgive me if there is something obvious im missing. Im …
How to Construct Daily Food Consumption ScoreDear Statalisters, I am working with a dataset that contains information on household consumption of…
Append regression results horizontallyHi, I am a new STATA user and found this forum has been incredibly helpful for me. I can't seem to …
Subscribe to:
Post Comments (Atom)
0 Response to random numbers to groups of random size
Post a Comment