Announcement

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

  • filter data use different group

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id month change)
    1  1 .
    1  2 .
    1  3 .
    1  4 .
    1  5 .
    1  6 6
    1  7 .
    1  8 .
    1  9 .
    1 10 .
    1 11 .
    1 12 .
    2  1 .
    2  2 .
    2  3 .
    2  4 .
    2  5 .
    2  6 .
    2  7 7
    2  8 .
    2  9 .
    2 10 .
    2 11 .
    2 12 .
    end
    ------------------ copy up to and including the previous line ------------------

    I want to keep data in every id when month > change, for example id 1 , change is 6 , then I want to result output month in ID 1 : 7 8 910 11 12


    so many thanks

  • #2
    Perhaps this will start you in a useful direction.
    Code:
    . bysort id (month): egen tokeep = min(change+1)
    
    . drop if month<tokeep
    (13 observations deleted)
    
    . list, noobs sepby(id)
    
      +------------------------------+
      | id   month   change   tokeep |
      |------------------------------|
      |  1       7        .        7 |
      |  1       8        .        7 |
      |  1       9        .        7 |
      |  1      10        .        7 |
      |  1      11        .        7 |
      |  1      12        .        7 |
      |------------------------------|
      |  2       8        .        8 |
      |  2       9        .        8 |
      |  2      10        .        8 |
      |  2      11        .        8 |
      |  2      12        .        8 |
      +------------------------------+

    Comment


    • #3
      Originally posted by William Lisowski View Post
      Perhaps this will start you in a useful direction.
      Code:
      . bysort id (month): egen tokeep = min(change+1)
      
      . drop if month<tokeep
      (13 observations deleted)
      
      . list, noobs sepby(id)
      
      +------------------------------+
      | id month change tokeep |
      |------------------------------|
      | 1 7 . 7 |
      | 1 8 . 7 |
      | 1 9 . 7 |
      | 1 10 . 7 |
      | 1 11 . 7 |
      | 1 12 . 7 |
      |------------------------------|
      | 2 8 . 8 |
      | 2 9 . 8 |
      | 2 10 . 8 |
      | 2 11 . 8 |
      | 2 12 . 8 |
      +------------------------------+
      Thank you so much William!

      Comment

      Working...
      X