Announcement

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

  • using randtreat for sampling without replacement

    Hello,
    I am trying to generate treatment assignments for a survey experiment where each respondent is asked the same question twice, but cannot be assigned to the same treatment arm twice. I have 5 arms and am using randtreat using the following code to assign assignments for the 1st time the question is asked. Is there a way to restrict the 2nd assignment to prevent the same treatment arm being assigned to a respondent?

    Code:
    randtreat, generate(treatment) replace strata(ea) mult(5) misfits(strata)

  • #2
    I do not use randtreat and I am not familiar with its workings. Here is a brute force approach that will loop until it finds a matching combination that satisfies your condition. You can set the iterations as high as you want as the loop will break once the condition is satisfied (assuming that this is possible). For 20 observations, 141 iterations were needed below.

    Code:
    clear
    set seed 09152022
    set obs 20
    g id=_n
    *START HERE
    g rand= rnormal()
    sort rand
    egen treat1= seq(), from(1) to(5)
    forval i=2/7e+6{
         g rand`i'= rnormal()
         sort rand`i'
         egen treat`i'= seq(), from(1) to(5)
         g cond= abs(treat1- treat`i')
         sort cond
         if cond[1]{
             continue, break
         }
         if !cond[1]{
             drop cond rand`i' treat`i'
         }
    }
    drop rand* cond
    sort id
    Res.:

    Code:
    . l, sep(0)
    
         +------------------------+
         | id   treat1   treat142 |
         |------------------------|
      1. |  1        5          2 |
      2. |  2        3          2 |
      3. |  3        1          4 |
      4. |  4        2          4 |
      5. |  5        3          4 |
      6. |  6        4          3 |
      7. |  7        5          2 |
      8. |  8        2          1 |
      9. |  9        1          5 |
     10. | 10        4          1 |
     11. | 11        4          1 |
     12. | 12        3          5 |
     13. | 13        1          5 |
     14. | 14        2          3 |
     15. | 15        2          3 |
     16. | 16        4          5 |
     17. | 17        5          3 |
     18. | 18        5          4 |
     19. | 19        3          1 |
     20. | 20        1          2 |
         +------------------------+
    Last edited by Andrew Musau; 15 Sep 2022, 05:51.

    Comment

    Working...
    X