Announcement

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

  • Randomization

    Hello, I am trying to randomize 100 obs into 3 groups with equal changes of being in either group.
    Group 1 = treatment
    Group 2= Control 1
    Group 3= Control 2
    I am trying to improve my current formula but in vain
    Here is my Current formula which is only generating only two groups

    gen number = uniform()
    centile (number), centile(50)
    gen treatment=1 if number>=r(c_1)
    replace treatment=2 if number<r(c_1)

  • #2
    The centile calculation is wrong in principle as the median you calculate (50% percentile) has no bearing on getting three approximately numerous groups. And you don't need it any way.

    The best you can do with 100 is 33 : 33 : 34, e.g. by

    Code:
    set seed 2803 
    gen double number = runiform() 
    sort number 
    gen treatment = cond(_n <= 33, 1, cond(_n <= 66, 2, 3))
    How you set a seed is immaterial, but setting a seed is a good idea for reproducibility.

    Comment


    • #3
      Thank you Nick Cox, Its working correctly. God Bless You.

      Comment


      • #4
        Hi Nick,

        I have a similar situation to Cyrus' post, although somewhat different.

        I would like to randomly assign 300 observations to 3 groups, using block sizes of 9 for the randomization. (ie. randomize the first 9 observations to the 3 groups, then randomize the second 9 observations, etc) I found some code on the old Stata forum and have modified it here, to work for my situation. I think it is doing what I want, but I just wanted to confirm that this approach seems appropriate.

        Thanks!
        Robin


        PHP Code:
        clear
        set obs 300
        egen arm 
        seq(), to(3)
        egen block seq(), block(9)
        set seed 15528
        gen random 
        uniform()
        bysort block (random): gen byte seqn _n
        *bysort block (seqn): list seqn arm random 

        Comment


        • #5
          Hello Robin, thanks for that i also got a way using:



          Code:
          bysort demo_district demo_treatment: gen random = runiform()
          sort random
          bysort demo_district demo_treatment: gen insample = _n <= 25
          *br demo_district random insample
          keep if insample==1



          Comment

          Working...
          X