Announcement

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

  • Random assignment within groups with a restricting condition

    I have data on the volume of transactions in markets and the market category.
    Code:
    input market_id market_volume str20 market_category
    1 100 "Big"
    2 100 "Big"
    3 50 "Medium" 
    4 50 "Medium" 
    5 10 "Small"
    6 10 "Small"
    end

    I wish to divide the markets into 2 groups randomly - Control and Test. However, it is important that:

    1. Each category will be roughly equally represented in the control and test groups.

    2. The number of transactions in the control and test groups will be roughly the same.

    Ideally, the random process would produce something like this:

    Code:
    input market_id market_volume str20 market_category random_assignment
    1 100 "Big"    1
    2 100 "Big"    0
    3 50 "Medium" 1
    4 50 "Medium" 0
    5 10 "Small" 1
    6 10 "Small" 0
    end

    How do I make this random assignment with the restrictions stated?

    Stata/MP 15.1

  • #2
    Dividing into groups using a uniform random number doesn't produce nearly equal means between the groups?

    Comment


    • #3
      Originally posted by Mor Zahavi View Post

      I wish to divide the markets into 2 groups randomly - Control and Test. However, it is important that:

      1. Each category will be roughly equally represented in the control and test groups.

      2. The number of transactions in the control and test groups will be roughly the same.
      \(\text{Random}\; +\; \text{restrictions}\; =\; \text{Non random}\). Consider an exaggerated example:

      Item 1: Weight 1: 20
      Item 2: Weight 2: 5000
      Item 3: Weight 3: 80
      Item 4: Weight 4: 100
      Item 5: Weight 5: 0

      I wish to randomly choose 2 items and I would like their weight to be 100. I pick items 1 and 3 or items 4 and 5. Fine, you may argue that I should toss a coin to choose between these two options. In any case, do random draws and keep those that satisfy your conditions. Then draw randomly among these.
      Last edited by Andrew Musau; 15 Feb 2022, 07:14.

      Comment


      • #4
        Code:
        g u = runiform()
        g group1 = u<0.5
        g group2 = 1 - group1

        Comment

        Working...
        X