Announcement

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

  • Constructing a new variable for the year of any labor market status after leaving full-time education

    Dear Stata Team,

    I have panel data (id, year), and I would like to construct a new variable call it the year after education "yae" for the first year of any labor market status after a person left full-time education (a person is in full-time education if jbstat==7).
    I would like to have an entry for this variable for all (survey) years for a given individual (id).
    Note that this variable "yae" is not necessarily always time-invariant for a given "id" (see id==17015) and can have a gap more than one year after full-time education (see id==17015).
    In such cases, "yae" will vary and should report for instance the first year after a person left full-time education, and the most recent year after a person left-full time education (see id==17015).
    Once again, I would highly appreciate your help in constructing this variable.
    Best,
    Nico


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long id float year byte jbstat
     2727 1992 2
     2727 1993 2
     2727 2000 2
     3407 1992 1
     3407 1993 1
     3407 1994 1
     3407 1998 1
     3407 1999 2
     3407 2001 2
     3407 2002 2
     3407 2005 2
     4091 1992 2
     4091 1993 2
     4091 1994 2
     4091 1995 2
     4767 1992 1
     4767 1993 1
     5451 1992 2
     5451 1993 2
     5451 1995 2
     6135 1993 2
     6807 1992 2
     6807 1993 2
     6882 1997 1
     6882 1998 2
     7487 1992 1
     7487 1993 1
     7487 1994 1
     7487 1996 1
     8167 1992 2
     8167 1993 2
     8167 1995 2
     8167 1996 2
     9527 1992 2
     9527 1993 2
     9527 1998 2
     9527 1999 2
     9527 2000 2
     9527 2002 2
     9527 2003 2
    12935 1992 7
    12935 1993 2
    12935 1998 2
    15645 1993 7
    15645 1994 2
    15645 1995 2
    15645 1996 2
    15645 1997 2
    15645 1998 2
    15645 1999 2
    15645 2000 2
    15645 2001 2
    15645 2002 2
    15645 2003 2
    15645 2004 2
    15645 2005 2
    15645 2006 2
    16339 1992 7
    16339 1993 2
    16339 1994 2
    16339 1995 2
    16339 1996 2
    16339 1997 2
    16339 1998 2
    16339 2005 2
    16339 2007 2
    17015 1999 7
    17015 2000 2
    17015 2001 7
    17015 2003 2
    17015 2004 2
    17015 2005 2
    20415 1992 7
    20482 1997 2
    21087 1992 2
    21087 1993 2
    21087 1994 2
    21087 1995 2
    21087 1996 2
    21087 1997 2
    21087 1998 2
    21087 2000 2
    21767 1992 2
    21767 1993 2
    21767 1994 1
    21767 1995 1
    21767 1996 2
    21767 1998 2
    21767 1999 1
    21767 2000 2
    21767 2002 2
    22445 2004 7
    22445 2005 2
    22445 2006 2
    22445 2007 2
    22445 2012 2
    22445 2013 2
    22445 2014 2
    22445 2015 2
    22445 2017 2
    end
    label values jbstat jbstat
    label def jbstat 1 "self-employed", modify
    label def jbstat 2 "employed", modify
    label def jbstat 7 "ft studt, school", modify

  • #2
    Code:
    //  CONSTRUCT RUNS OF EDUCATION VS NON-EDUCATION YEARS
    by id (year), sort: gen run = sum((jbstat == 7) != (jbstat[_n-1] == 7))
    
    //  SET yae TO THE YEAR STARTING EACH NON-EDUCATION RUN
    by id run (year), sort: gen yae = cond(jbstat[1] != 7, year[1], .)

    Comment


    • #3
      That works just fine, thank you very much Clyde!
      Have a great day,
      Best,
      Nico

      Comment

      Working...
      X