Announcement

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

  • reshape with combination

    Dear All, I found this question here (in Chinese). The dataset is:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float id str4 x
    1 "a"
    1 "b"
    1 "c"
    2 "a"
    2 "b"
    end
    and the desired result is:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float id1 str4(x1 x2)
    1 "a" "b"
    1 "a" "c"
    1 "b" "c"
    2 "a" "b"
    end
    Within each `id', use the elements in `x' to form different combinations in `x1' and `x2'. Any suggestions are highly appreciated.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float id str4 x
    1 "a"
    1 "b"
    1 "c"
    2 "a"
    2 "b"
    end
    
    preserve
    rename x x2
    tempfile b
    save `b'
    restore
    joinby id using `b'
    keep if x<x2
    Res.:

    Code:
    . l
    
         +-------------+
         | id   x   x2 |
         |-------------|
      1. |  1   a    c |
      2. |  1   a    b |
      3. |  1   b    c |
      4. |  2   a    b |
         +-------------+

    Comment


    • #3
      Dear Andrew, Thanks a lot for this helpful suggestion.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment

      Working...
      X