Announcement

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

  • Simple Random Sampling Without Replacement

    I have a dataset where I want to allocate 80 % of the sample drawn to Person A and the Rest 20 % is to both Person A and B. Could anyone please help me with which command to use and how to create two different datasets for persons A and B with the criteria?


  • #2
    I will assume that you want to draw 80% of the observations and create a dataset and thereafter do a second drawing from the remaining 20%. Do you allocate the same number of observations to A and B in the second drawing? If so, how is that different from drawing 90% of the observations for A and the remaining 10% for B?

    Code:
    clear
    set obs 100
    set seed 06202022
    gen sample= runiformint(1, 100)
    list, sep(0)
    *START HERE
    gen random= rnormal()
    *ALLOCATION: 90% TO A
    sort random
    frame put sample in 1/`=int(0.9*`=_N')', into(A)
    frame put sample in `=int(0.9*`=_N') +1'/ l, into(B)
    frame A: list, sep(0)
    frame B: list, sep(0)
    Res.:

    Code:
    . list, sep(0)
    
         +--------+
         | sample |
         |--------|
      1. |      2 |
      2. |     46 |
      3. |     15 |
      4. |     50 |
      5. |     79 |
      6. |     82 |
      7. |     50 |
      8. |     38 |
      9. |     21 |
     10. |     96 |
     11. |     51 |
     12. |     17 |
     13. |     12 |
     14. |     77 |
     15. |     15 |
     16. |     43 |
     17. |     14 |
     18. |     59 |
     19. |     12 |
     20. |     57 |
     21. |     28 |
     22. |     55 |
     23. |     30 |
     24. |     70 |
     25. |     55 |
     26. |     36 |
     27. |     20 |
     28. |      6 |
     29. |     28 |
     30. |     52 |
     31. |    100 |
     32. |     98 |
     33. |      2 |
     34. |     36 |
     35. |     24 |
     36. |     83 |
     37. |     98 |
     38. |     64 |
     39. |     83 |
     40. |      8 |
     41. |      6 |
     42. |      1 |
     43. |     28 |
     44. |     90 |
     45. |     82 |
     46. |     89 |
     47. |     26 |
     48. |     50 |
     49. |      4 |
     50. |     17 |
     51. |     95 |
     52. |     51 |
     53. |     28 |
     54. |     92 |
     55. |     44 |
     56. |      3 |
     57. |     72 |
     58. |     53 |
     59. |     53 |
     60. |     99 |
     61. |     41 |
     62. |     19 |
     63. |     62 |
     64. |     23 |
     65. |     81 |
     66. |     43 |
     67. |     49 |
     68. |     26 |
     69. |     28 |
     70. |     47 |
     71. |     55 |
     72. |     95 |
     73. |     84 |
     74. |     27 |
     75. |     99 |
     76. |     44 |
     77. |     78 |
     78. |      8 |
     79. |     83 |
     80. |     74 |
     81. |     93 |
     82. |     51 |
     83. |     81 |
     84. |     22 |
     85. |     81 |
     86. |     83 |
     87. |     65 |
     88. |     16 |
     89. |     57 |
     90. |     48 |
     91. |     33 |
     92. |     89 |
     93. |     82 |
     94. |     76 |
     95. |     22 |
     96. |     37 |
     97. |     28 |
     98. |     94 |
     99. |     57 |
    100. |     53 |
         +--------+
    
    .
    . *START HERE
    
    .
    . gen random= rnormal()
    
    .
    . *ALLOCATION: 90% TO A
    
    . frame A: list, sep(0)
    
         +--------+
         | sample |
         |--------|
      1. |     53 |
      2. |     72 |
      3. |     82 |
      4. |     84 |
      5. |     55 |
      6. |     82 |
      7. |     28 |
      8. |     50 |
      9. |     96 |
     10. |     44 |
     11. |     83 |
     12. |      6 |
     13. |      4 |
     14. |     94 |
     15. |     81 |
     16. |    100 |
     17. |      8 |
     18. |     14 |
     19. |     57 |
     20. |     19 |
     21. |     48 |
     22. |     28 |
     23. |     77 |
     24. |     28 |
     25. |      6 |
     26. |     28 |
     27. |     81 |
     28. |     24 |
     29. |     22 |
     30. |     26 |
     31. |     22 |
     32. |     55 |
     33. |     44 |
     34. |     38 |
     35. |      2 |
     36. |     51 |
     37. |     98 |
     38. |     89 |
     39. |      3 |
     40. |     17 |
     41. |     52 |
     42. |     64 |
     43. |     50 |
     44. |     65 |
     45. |     93 |
     46. |     43 |
     47. |     89 |
     48. |     33 |
     49. |     83 |
     50. |     26 |
     51. |     82 |
     52. |     12 |
     53. |     81 |
     54. |     23 |
     55. |     37 |
     56. |     16 |
     57. |     57 |
     58. |      8 |
     59. |     53 |
     60. |     90 |
     61. |     50 |
     62. |     95 |
     63. |     55 |
     64. |     17 |
     65. |     46 |
     66. |     21 |
     67. |     15 |
     68. |     74 |
     69. |     99 |
     70. |     83 |
     71. |     28 |
     72. |     98 |
     73. |     57 |
     74. |     78 |
     75. |      1 |
     76. |     99 |
     77. |     49 |
     78. |     20 |
     79. |     12 |
     80. |     51 |
     81. |     41 |
     82. |     36 |
     83. |     95 |
     84. |     47 |
     85. |     36 |
     86. |     70 |
     87. |     27 |
     88. |     30 |
     89. |     62 |
     90. |     92 |
         +--------+
    
    . 
    . frame B: list, sep(0)
    
         +--------+
         | sample |
         |--------|
      1. |     15 |
      2. |     59 |
      3. |     76 |
      4. |     79 |
      5. |     83 |
      6. |     43 |
      7. |      2 |
      8. |     51 |
      9. |     28 |
     10. |     53 |
         +--------+
    
    .
    Last edited by Andrew Musau; 20 Jun 2022, 08:06.

    Comment


    • #3
      Thank you! It was very helpful.

      Comment

      Working...
      X