Announcement

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

  • Dropping variables that change in a longitudinal survey

    I will try to be brief.

    Race fixed effects have changed in my 4 different years. In the first survey some individuals that answered black for example changed to Asian Black in the year after.

    How can I delete all these observations that show different answers in different years?
    I just want to remove all the individuals that answered two different things in the survey
    • For example the same Person (PersonNum=1109) answered: Race=101 in T1 , Race 102 in T2 , Race 101 in T3 .
    or for example
    • For example the same Person (PersonNum=20013) answered: Race=101 in T1 , Race=missing in T2 , Race 101 in T3
    For both scenarios I need to drop them


    Is there someone that can give me a quick guidance code, Im new with Stata
    Last edited by Roberto Villa; 13 Mar 2022, 09:42.

  • #2
    Assuming that the person and survey wave variables here are named "id" and "wave," one common way to do this is:
    Code:
    bysort id (race):  gen byte racevaries = (race[1] != race[_N])
    drop if racevaries == 1  // will work, but not a great idea
    // Better:
    RunSomeAnalysis if (racevaries == 0)
    Note that if an individual's race is missing in all waves, this variable won't catch it.

    In Stata terminology, what is being done here involves identifying *observations* to be dropped, not *variables.* That clarification might help you in making sense of Stata documentation.
    Last edited by Mike Lacy; 13 Mar 2022, 09:36.

    Comment


    • #3
      Sorry Mike Lacy but this also accounts for the following:
      • For example the same Person (PersonNum=1109) answered: Race=101 in T1 , Race 102 in T2 , Race 101 in T3 .
      or for example
      • For example the same Person (PersonNum=20013) answered: Race=101 in T1 , Race=missing in T2 , Race 101 in T3
      For both scenarios I need to drop them

      Comment


      • #4
        See the concurrent thread https://www.statalist.org/forums/for...-type-industry and its links.

        Comment


        • #5
          Roberto Villa
          Perhaps I misunderstood what you intended. In your second post, I'm guessing that you might mean that those two persons you described are *not* handled the way you want by the code I suggested. I'm confused because that code does mark them as having responses for race that vary across time.
          Code:
          . input int PersonNum byte T race
               Person~m         T       race
            1. 1109 1 101
            2. 1109 2 102
            3. 1109 3 101
            4. 20013 1 101
            5. 20013 2 .
            6. 20013 3 101
            7. end
          . //
          . bysort PersonNum (race):   gen byte racevaries = (race[1] != race[_N])
          
          . list
               +--------------------------------+
               | Person~m   T   race   raceva~s |
               |--------------------------------|
            1. |     1109   1    101          1 |
            2. |     1109   3    101          1 |
            3. |     1109   2    102          1 |
            4. |    20013   1    101          1 |
            5. |    20013   3    101          1 |
               |--------------------------------|
            6. |    20013   2      .          1 |
               +--------------------------------+

          Comment


          • #6
            Sorry Mike Lacy I appreciate your response , yes the


            | Person~m T race raceva~s | |--------------------------------| 1. | 1109 1 101 1 | 2. | 1109 3 101 1 | 3. | 1109 2 102 1 | 4. | 20013 1 101 1 | 5. | 20013 3 101 1 | |--------------------------------| 6. | 20013 2 . 1


            7 105 1 101 1
            8. 105 2 101 1
            9. 105 3 101 1

            In this example , I just want to include observation 105 , I want to drop 1109 2013 , due to missing value and because of error in answer.


            Thank you for your response


            Roberto

            Comment


            • #7
              This question was reposted at

              https://www.statalist.org/forums/for...-fixed-effects

              with subsequent discussion.

              Comment

              Working...
              X