Announcement

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

  • drop individuals by the condition


    hello everyone,

    could anyone help me to find an appropriate command for the following condition:

    I have dummy variables zero and one, I want to drop firms that have not dummy variable one in all year.

    for example, I have the following dataset

    id year dummy
    1 2000 1
    1 2001 1
    1 2002 0
    1 2003 0
    1 2004 0
    1 2005 1
    2 2000 0
    2 2001 0
    2 2002 0
    2 2003 0
    2 2004 0
    3 20050

    So I want to keep id 1 because there is dummy variable one in some years and I want to drop id 2 because all years have dummy zero and so on.

    Could anyone help me to find the command?




  • #2
    Question is inconsistent: is the criterion 1 in all years or 1 in some years?

    For all years

    Code:
    bysort id (dummy) : drop if dummy[1] == 0
    For some years

    Code:
    bysort id (dummy) : keep if dummy[_N] == 1

    Comment


    • #3
      Dear Nick Cox

      Thank you very much

      Comment

      Working...
      X