Announcement

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

  • Pair Combination with Repeat Observation

    Hi all,

    I have dataset:
    A B C
    1 2 45
    1 3 46
    1 4 47
    2 3 .
    2 4 .
    and I want to repeat the observation that result like this table below:
    A B C
    1 2 45
    1 2 46
    1 2 47
    1 3 45
    1 3 46
    1 3 47
    1 4 45
    1 4 46
    1 4 47
    2 3 45
    2 3 46
    2 3 47
    2 4 45
    2 4 46
    2 4 47

    I try to use stack command, but it doesn't work (I refer the command from this post https://www.statalist.org/forums/for...r-combinations)
    Could anybody give me a clue on how to solve it?
    Thank you.

    Regards.
    Khresna

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(A B C)
    1 2 45
    1 3 46
    1 4 47
    2 3  .
    2 4  .
    end
    
    preserve
    contract C, nomiss
    drop _freq
    tempfile C
    save `C'
    restore
    drop C
    cross using `C'
    Res.:

    Code:
    . sort A B C
    
    . l, sepby(A)
    
         +------------+
         | A   B    C |
         |------------|
      1. | 1   2   45 |
      2. | 1   2   46 |
      3. | 1   2   47 |
      4. | 1   3   45 |
      5. | 1   3   46 |
      6. | 1   3   47 |
      7. | 1   4   45 |
      8. | 1   4   46 |
      9. | 1   4   47 |
         |------------|
     10. | 2   3   45 |
     11. | 2   3   46 |
     12. | 2   3   47 |
     13. | 2   4   45 |
     14. | 2   4   46 |
     15. | 2   4   47 |
         +------------+

    Comment


    • #3
      Hi Andrew,
      your code is work.
      Thank you for your help..I really appreciate it


      Comment

      Working...
      X