Announcement

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

  • About how to store things in an object

    Hi this is a starter of stata. I'm dealing with a panel dataset and I would like to drop those individuals with specific features, but these features only appear in some of the years. I'm thinking about saving the id of these individuals into something like a vector but I have no idea how to do it in Stata.

  • #2
    At this level of generality is hard to say anything in particular.

    Try to come up with some toy example that illustrates your problem, and present a toy dataset using -dataex-.

    Comment


    • #3
      Suppose you start by creating a variable which we will call features that takes the value 1 if the observation has the features that would cause you to want to drop all the years for that individual. And suppose your panel data is identified by the variables id and year. Then
      Code:
      by id (year), sort: egen todrop = max(features)
      Then todrop will take the value 1 for every observation of an individual who has at least one observation with features==1, and will otherwise take the value 0 for every observation of the individual. Then
      Code:
      drop if todrop==1
      will do what you seek.

      Comment


      • #4
        Originally posted by William Lisowski View Post
        Suppose you start by creating a variable which we will call features that takes the value 1 if the observation has the features that would cause you to want to drop all the years for that individual. And suppose your panel data is identified by the variables id and year. Then
        Code:
        by id (year), sort: egen todrop = max(features)
        Then todrop will take the value 1 for every observation of an individual who has at least one observation with features==1, and will otherwise take the value 0 for every observation of the individual. Then
        Code:
        drop if todrop==1
        will do what you seek.
        Great idea! Thank you very much.

        Comment

        Working...
        X