Announcement

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

  • Shifting down observations when reshaping data to long format

    Morning,

    I am working with some Chilean longitudinal data that has quite rich data on participants work history. I have information on their previous employment, down to the year and month they started and ended each employment activity. I want to create a panel with these observations for every month, I already have the date variable sorted, and no problem carrying over observations for each row when the employment doesn't change.

    However, for the individuals who have multiple activities, I need to shift down the start / finish dates to correspond with my date variable, as is the case with the individual in the example. Therefore is there anyway to do this, conditioning on whether the start_date is less or equal to the date or something?

    Any help/advice is greatly appreciated. Thanks.
    Attached Files

  • #2
    Okay apologies I have sorted it now, perhaps not the most 'majestic' method but I'll leave this here in case it helps anyone else in the future.

    Starting with the last row for each individual (most recent job activity) I carryedforward the observations IF the row below was missing. I then generated a dummy variable 'inbetween' that took the value one if the start_date and end_date encapsulated the date variable. I then dropped all observations where inbetween != 1. I had to create an indicator for the row which I started with though, otherwise stata would also drop other activities that I had yet to shift down, based on the inbetween condition.

    I then created a while loop to do this iteratively for the remaining activities until all rows where filled out and everything was in its corresponding position.

    Comment

    Working...
    X