Announcement

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

  • Matching different ID between two periods

    Hi!
    I have a problem that I wonder if anybody can help me with.

    I have panel data of individuals were the time period is 2 years. Each individual have a unique identification number (indID) and a house ID which is unique in each region but different regions can have the same number.
    What I want to do now is to see if an individual have moved to a new house or not (coded as a 1) and thus changed house ID (there is a theoretical chance that a person moves between two houses with the same house ID but different regions).

    I don't know how to solve this but a first start is the following.

    xtset indID year

    bysort indID: gen Change=1 if house ID!=houseID[_n+1]

    My problem with this code is that it gives a 1 in all houses in period 2, independently if houseID have changed or not.
    Any good advice or alternative solutions?


  • #2
    Code:
    bysort indID (year): gen Change=  (houseID[1]!=houseID[2])|(region[1]!=region[2]) & _N==2
    See

    Code:
    help operators
    The pipe here indicates "or", the rationale being that if you changed regions, you no longer reside in the same house.
    Last edited by Andrew Musau; 16 May 2023, 08:27.

    Comment


    • #3
      Thank you Andrew, it worked perfectly!

      Best
      David

      Comment


      • #4
        Just a clarification, if I would like to do the same but for severeal periods (say 10). And each pair of years will do the same, how should I do it then?

        Comment

        Working...
        X