Announcement

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

  • Dropping all observations on an individual under certain conditions

    Hi there,

    I am using panel data on employment, and want to delete all observations on a specific individuals if, when that individual is first observed. they are unemployed. So far, I have a dummy variable called 'unemployed' which equals 1 if that individual is unemployed at that point in time. I also have a variable called 'first' which equals 1 the first time the person's ID appears.

    However, I can't work out how to get STATA to drop all observations on an individual if they are unemployed during the first observation. I have tried ''drop if unemployed==1 & first==1'' but that only drops that observation on the individual, not all observations on that individual.

    I would greatly appreciate any help! Thanks!

  • #2
    Try
    Code:
    bysort individual (first): drop if first[1]==1 & unemployed[1]==1

    Comment


    • #3
      I don't think Roger's code will do what Jay wants. The problem is that when you sort on first within individual, first being a zero/one variable, the observation where first == 1 will sort last. So first[1] will only equal 1 if the first observation on the individual is also the last! If a person has been observed more than once, then first[1] will always be zero and no -drop- will take place. I think the fix is easy enough:

      Code:
      bysort individual (first): drop if first[_N] == 1 & unemployed[_N] == 1
      Note: This assumes that first is actually 0/1 and never has missing values.

      Comment


      • #4
        Clyde is correct. If first is a dummy that takes on values 0/1, then my code is incorrect, and his is correct.

        If first is just a tagging variable, with 1's and missing values, then my code would work correctly.

        It all depends on how first is set up!
        Last edited by Roger Chu; 30 Mar 2017, 10:00. Reason: Also wanted to say, "nice catch," to Clyde!

        Comment


        • #5
          This has solved my problem. Honestly, thank you so much!

          Comment

          Working...
          X