Announcement

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

  • Indicate a change in a variable between two periods

    Hi,
    I have a problem were I want to identify if a variable from an individual change between 2 periods (t - t+1). The variable that I want to observe is if a houseID change. The maximum number of years are 10 but it´s not a balanced sample, were some individuals only have a value 1 period. The data is panel data.

    The problem I have with my code is that independently if there is a change or not, the data indicates a 1 in the last period for all individuals. I don´t know how to solve this. Bellow is the code that I use.





    gen change = 0
    bysort individualID (year): replace change = 1 if houseID!=houseID(_n+1)


    Best
    David

  • #2
    For the last observation you obviously cannot know whether the non-existent next observation has the same houseID or not. So the correct value should be missing.

    Code:
    bysort individualID (year) : gen change = 0 if _n != _N
    bysort individualID (year): replace change = 1 if houseID!=houseID(_n+1) & _n != _N
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks for the reply Maarten, and you are off course right with the missing value. I guess that is what the last part does, if _n!= _N. I am a bit unfamiliar with the use of n and N. Say that we would like the first period to have a missing values, how would we code it then? For example a set up were the specification is houseID!=houseID[_n-1]

      Also, just so I did it correctly, when I used ( ) I got a error message "unknown function houseID( )", while changing to [ ] it worked fine. Is that right?


      Best
      David

      Comment

      Working...
      X