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
Continuous or discrete variable?Hello. I have a question regarding a variable I have constructed. For a number of countries, I have…
Plotting result of table functionSorry a very basic question. To get a table I run: table year city [pw=E], c(mean W) and get the …
How to adjust standard errors using wild t-bootstrapping?I am running some regressions with number of clusters 29. I believe due to low number of clusters I …
Descriptive statistic in panel analysis multiple ifsHello to all, I’m using STATA 16. I have a panel data frame with 2 waves. Before and while the Coron…
Formatting Local with Date in Graph NoteHello everyone, I want to include the date of last data actualization in the notes of a graph. Ther…
Subscribe to:
Post Comments (Atom)
0 Response to random numbers to groups of random size
Post a Comment