Announcement

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

  • Replacing in the context of long data

    For the below sample data, I would like to drop an id if one of its rows contains the value of 7(i.e., id=2, 4, and 5).


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(id year status)
    1 2000 1
    1 2002 2
    1 2004 2
    2 2002 1
    2 2004 7
    3 2000 2
    4 2000 1
    4 2002 7
    5 2000 7
    end



  • #2
    I hope the below helps.

    Code:
    sort id
    
    // Create a new indicator variable for id if one of its statuses is 7
    egen has_status7 = max(status == 7), by(id)
    
    drop if has_status7 == 1
    drop has_status7

    Comment


    • #3
      Originally posted by Navi Reddy View Post
      I hope the below helps.

      Code:
      sort id
      
      // Create a new indicator variable for id if one of its statuses is 7
      egen has_status7 = max(status == 7), by(id)
      
      drop if has_status7 == 1
      drop has_status7
      Great! Thanks. How can I obtain the frequency for the ids (i.e., not rows) with status==7?

      Comment


      • #4
        How about

        Code:
        tabulate id if status == 7
        ?

        Comment

        Working...
        X