Announcement

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

  • keep same values?

    Dear all, I found this question here (http://bbs.pinggu.org/thread-6752140-1-1.html). The data is:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id x)
    1 3
    1 4
    1 5
    1 6
    2 3
    2 4
    2 7
    2 8
    end
    There are only two groups for `id' (1 or 2). For `id=2', I'd like to keep the observations where the values of `x' of `id=2' appear in the values of `x' of `id=1'. The desired result is
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id x)
    1 3
    1 4
    1 5
    1 6
    2 3
    2 4
    end
    Any suggestions?
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id x)
    1 3
    1 4
    1 5
    1 6
    2 3
    2 4
    2 7
    2 8
    end
    
    
    by x (id), sort: drop if id == 2 & _N == 1
    sort id x
    
    list, noobs sepby(id)
    Hat tip @Romalpa Akzo.

    Comment


    • #3
      Dear Clyde, Thanks a lot for this interesting suggestion.
      Ho-Chuan (River) Huang
      Stata 17.0, MP(4)

      Comment

      Working...
      X