Announcement

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

  • Track an id over time

    Hi everyone,

    I come to ask for some advice.

    I have a dataset composed by all individuals (tracked by their id) working in entreprises for each year worked. That means that the individual is not registered in the dataset if he is not part of an enterprise for one or multiple specific years. I also have a variable "displacement" coded 1 if the individual has disappeared from the dataset (for a given entreprise). Here is an example of my dataset for two individuals


    id enterprise year Displacement

    5 A 1998 .
    5 A 1999 .
    5 A 2000 .
    5 A 2001 1
    5 B 2005 .
    5 B 2006 .
    6 A 1999 .
    6 A 2000 1 .
    6 C 2002 .
    6 C 2003 .

    I would like to identify by a variable the reemployment of individuals that have been displaced (displacement=1) from the panel and reappeared after in another entreprise. I would like to account also for the number of years that it took to the individual to find another job (year of reemployment - year of displacement). For the moment, the only solution I found is:

    - I created a variable id x entreprise
    - I look only at individuals that have been displaced
    - For each year n, I cut the file to keep the year n + the year after, to look for reemployment one year after.
    - I identify the year that the id x entreprise appears for the last time
    - I identify the year that the id appears for the last time (because the last id x entreprise will necessarily be the year n as I took only individuals that have been displaced from their entreprise so if the year of appearance of the individual is different, that mean he appears the year after so that he found a job in another entreprise)
    - If the year is different, that means that the individual has been reemployed
    - I repeat the operation for each year but I take two years after the displacement

    Nevertheless, that obliges me to create several files and it is a very complex and a very cumbersome operation.

    I would like to know if you see another way to do this in one file only.

    I would very grateful if you could help me

    Kindly,

    Eugénie

  • #2
    I'm not sure I understand your question correctly, but if I do, then this would do it:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte id str1 enterprise int year byte(displacement var5)
    5 "A" 1998 . .
    5 "A" 1999 . .
    5 "A" 2000 . .
    5 "A" 2001 1 .
    5 "B" 2005 . .
    5 "B" 2006 . .
    6 "A" 1999 . .
    6 "A" 2000 1 .
    6 "C" 2002 . .
    6 "C" 2003 . .
    end
    
    replace displacement = 0 if missing(displacement)
    by id (year), sort: gen byte reappearance = displacement[_n-1] ///
        & enterprise != enterprise[_n-1]
    by id (year): gen number_of_years = year - year[_n-1] if reappearance
    Note: Having a variable coded 1/. is bad practice in Stata and leads to mistakes. Dichotomies should be coded 1/0. I have made that change as the first command above. This is also critical to the proper functioning of this solution: this code will give wrong answers if displacement is left as 1 vs missing value.

    In the future, when posting a data example, please use the -dataex- command, as I have done here. Run -ssc install dataex- to get the -dataex- command, and then run -help dataex- to see the very simple instructions for using it. By using -dataex- you enable those who want to help you to create a complete and faithful replica of your Stata example in their own Stata with a simple copy/paste operation. This makes it possible to develop and test code for a solution with the assurance that it will work with your data.

    Comment

    Working...
    X