Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • create a unique random integer.

    Hello, I want to create a unique random integer.
    I have 34 observations and I wish to have for each observation a number between 1 and 34 which is not identical to the observation


    Here is my code: With this code, no data is modified in the table

    gen expert= runiformint(1, 34)
    bysort expert: gen doublon=_n

    while doublon!=1 | a==expert{
    replace expert= runiformint(1, 34)
    drop doublon
    bysort expert: gen doublon=_n }




    Example: I don't want the errors in lines 4 and 5
    a expert doublon
    1 11 1
    2 6 1
    3 15 1
    4 15 2
    5 5 1
    Last edited by Cyprienne Boedard; 18 Jan 2022, 04:43.

  • #2

    Code:
    set seed 18012022 
    gen double random = runiform()
    sort random 
    gen wanted = _n 
    isid wanted

    Comment


    • #3

      Thank you, I did not know these formulas set seed and isid !

      Comment

      Working...
      X