Announcement

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

  • Creating variables to measure transitions

    Dear Statalist Users,

    I have longitudinal data - 15 waves. I'm interested in looking at transitions in labour force status over time. I want to know the effect of transitions in labour force status over time on my dependent measure (general health and well-being) for example, FT at t-1 and Unemployed at t-t; part-time at t-1 and not in the labour force at t-2. I always want to make variables that show no transitions, e.g. full-time at t-1 and t-2. The employment variable is a categorical variable: [1] employed, full-time; [2] employed, part-time; [3] unemployed; and [4] not in the labour force.

    I'm unsure of the syntax to capture these transitions.

    Any help would be great appreciated

    Best
    Brendan

  • #2
    My opinion is that it will be difficult to argue that it is the transition that affects well-being and not the state (i.e., for example being employed relative to unemployed). If you measure well-being by comparing self-reported scores from an ordinal scale (e.g., 0 to 10 indexing very unsatifsifed/ unhealthy to very satified/ healthy), Winkelmann and Winkelmann (1998) argue that what is problematic is inter-personal comparison of scores (a score of 3 for you may not be the same as a score of 3 for me). With repeated measures of the same individual over time, they suggest intra-personal comparison of scores (fixed effects). So one way to approach your issue may be to define two transitions, e.g., downward transition meaning one transitions from full time to either part time or unemployed, and from part-time to unemployed. On the other hand, upward transition would be in the opposite direction. Then you can compare reported outcomes of individuals in states that follow a downward transition with those in states that follow an upward transition. In effect, the employed and unemployed will be in separate groups but the part-time employed will be split into different groups. You may also create multiple groups indicating each transition separately if you find it interesting to study each transition on its own. Present a data example if you are finding it difficult to create the groups.


    Winkelmann, L., and R. Winkelmann. “Why are the unemployed so unhappy? Evidence from
    panel data.” Economica 65:257 (1998): 1–15.

    Comment


    • #3
      I have provided the example - I want to create variable that capture people going from FT at t-1 to UNEMP at t-t but I am sure of how to do that with a categorical variable in Stata.

      Comment


      • #4
        I see no data example. I suggest that you search the forum specifying keywords data example and dataex for examples.

        Comment


        • #5
          Example:

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input byte(losatyh esdtl)
           5 6
           6 2
           5 2
           6 2
           4 2
           4 2
           5 2
           8 2
           8 2
           8 2
           7 2
           8 1
           6 1
           7 3
           6 1
           8 5
           7 2
           8 2
           4 6
           5 5
           2 6
           5 6
           5 6
          10 2
           8 2
           9 2
           8 2
          10 2
           8 2
           8 2
           8 2
           8 2
           8 6
           8 5
           7 6
           7 5
           7 3
           6 4
           8 3
           7 5
           7 2
           8 4
           7 4
           7 2
           6 2
           8 1
           7 2
           5 2
           7 1
           7 6
           4 2
           5 2
           7 2
          10 4
          10 2
           9 3
          10 6
          10 5
           6 6
           5 6
           5 6
           6 6
           8 6
           7 6
           5 6
           2 6
           2 6
           1 6
           3 6
           1 6
           5 6
          10 1
          10 2
           9 2
           8 2
           8 2
           5 5
           8 3
           5 5
           1 6
           5 2
           5 2
           7 1
           5 2
           6 2
           6 2
           8 5
           8 5
           8 5
          10 5
           6 6
           7 6
           7 5
           4 2
           6 5
           5 1
           6 1
           7 1
           7 1
           7 1
          end
          label values losatyh OLOSATYH
          label def OLOSATYH 5 "[5] Neither satisfied nor dissatisfied", modify
          label def OLOSATYH 10 "[10] Totally satisfied", modify
          label values esdtl OESDTL
          label def OESDTL 1 "[1] Employed FT", modify
          label def OESDTL 2 "[2] Employed PT", modify
          label def OESDTL 3 "[3] Unemployed, looking for FT work", modify
          label def OESDTL 4 "[4] Unemployed, looking for PT work", modify
          label def OESDTL 5 "[5] Not in the labour force, marginally attached", modify
          label def OESDTL 6 "[6] Not in the labour force, not marginally attached", modify

          Comment


          • #6
            Thanks for the data example. What you lack in the example is a panel identifier and a time variable but I will create these. So the following illustrates how to create an indicator variable for observations following a transition from full-time to part-time work which you can adapt for other transitions.

            Code:
            
            *GENERATING ID AND TIME VARIABLES (SHOULD BE PRESENT IN YOUR DATASET)
            egen id= seq(), block(10)
            bys id: gen year= 2007 + _n
            
            *GENERATE VARIABLE THAT IDENTIFIES ANY KIND OF TRANSITION
            bys id (year): gen transition = cond( esdtl[_n] !=esdtl[_n-1], 1, 0 )
            bys id (year): replace transition=0 if _n==1
            
            
            *GENERATE INDICATOR FOR INDIVIDUALS WITH NO TRANSITION 
            by id: egen NT= min(cond(transition==1), 0, 1)
            
            *GENERATE INDICATOR FOR OBS. FOLLOWING FULL-TIME TO PART-TIME TRANSITION
            *(i.e., transition from esdtl=1 to  esdtl=2 in your dataset)
            
            bys id (year): gen FT2PT= cond(transition==1 & esdtl[_n-1]==1 & esdtl==2, 1, 0)
            
                   
            *REPLACE VALUES OF PART TIME AND NO TRANSITION FOLLOWING FULL TIME TO 1
            bys id (year): replace FT2PT= FT2PT[_n-1] if esdtl==2 & transition==0
            replace FT2PT=0 if missing(FT2PT)

            Here you see individual with id=7 has no transition whereas those who have a transitition from FT to PT are identified by the variable FT2PT (for years following the transition). An additional note is that it may be best to xtset your data and use time-series operators if you have an unbalanced panel (missing years for some individuals in the panel).

            Code:
            
            . l esdtl id year transition NT FT2PT, sepby(id)
            
                 +------------------------------------------------------------------------------------------+
                 |                                                esdtl   id   year   transi~n   NT   FT2PT |
                 |------------------------------------------------------------------------------------------|
              1. | [6] Not in the labour force, not marginally attached    1   2008          0    0       0 |
              2. |                                      [2] Employed PT    1   2009          1    0       0 |
              3. |                                      [2] Employed PT    1   2010          0    0       0 |
              4. |                                      [2] Employed PT    1   2011          0    0       0 |
              5. |                                      [2] Employed PT    1   2012          0    0       0 |
              6. |                                      [2] Employed PT    1   2013          0    0       0 |
              7. |                                      [2] Employed PT    1   2014          0    0       0 |
              8. |                                      [2] Employed PT    1   2015          0    0       0 |
              9. |                                      [2] Employed PT    1   2016          0    0       0 |
             10. |                                      [2] Employed PT    1   2017          0    0       0 |
                 |------------------------------------------------------------------------------------------|
             11. |                                      [2] Employed PT    2   2008          0    0       0 |
             12. |                                      [1] Employed FT    2   2009          1    0       0 |
             13. |                                      [1] Employed FT    2   2010          0    0       0 |
             14. |                  [3] Unemployed, looking for FT work    2   2011          1    0       0 |
             15. |                                      [1] Employed FT    2   2012          1    0       0 |
             16. |     [5] Not in the labour force, marginally attached    2   2013          1    0       0 |
             17. |                                      [2] Employed PT    2   2014          1    0       0 |
             18. |                                      [2] Employed PT    2   2015          0    0       0 |
             19. | [6] Not in the labour force, not marginally attached    2   2016          1    0       0 |
             20. |     [5] Not in the labour force, marginally attached    2   2017          1    0       0 |
                 |------------------------------------------------------------------------------------------|
             21. | [6] Not in the labour force, not marginally attached    3   2008          0    0       0 |
             22. | [6] Not in the labour force, not marginally attached    3   2009          0    0       0 |
             23. | [6] Not in the labour force, not marginally attached    3   2010          0    0       0 |
             24. |                                      [2] Employed PT    3   2011          1    0       0 |
             25. |                                      [2] Employed PT    3   2012          0    0       0 |
             26. |                                      [2] Employed PT    3   2013          0    0       0 |
             27. |                                      [2] Employed PT    3   2014          0    0       0 |
             28. |                                      [2] Employed PT    3   2015          0    0       0 |
             29. |                                      [2] Employed PT    3   2016          0    0       0 |
             30. |                                      [2] Employed PT    3   2017          0    0       0 |
                 |------------------------------------------------------------------------------------------|
             31. |                                      [2] Employed PT    4   2008          0    0       0 |
             32. |                                      [2] Employed PT    4   2009          0    0       0 |
             33. | [6] Not in the labour force, not marginally attached    4   2010          1    0       0 |
             34. |     [5] Not in the labour force, marginally attached    4   2011          1    0       0 |
             35. | [6] Not in the labour force, not marginally attached    4   2012          1    0       0 |
             36. |     [5] Not in the labour force, marginally attached    4   2013          1    0       0 |
             37. |                  [3] Unemployed, looking for FT work    4   2014          1    0       0 |
             38. |                  [4] Unemployed, looking for PT work    4   2015          1    0       0 |
             39. |                  [3] Unemployed, looking for FT work    4   2016          1    0       0 |
             40. |     [5] Not in the labour force, marginally attached    4   2017          1    0       0 |
                 |------------------------------------------------------------------------------------------|
             41. |                                      [2] Employed PT    5   2008          0    0       0 |
             42. |                  [4] Unemployed, looking for PT work    5   2009          1    0       0 |
             43. |                  [4] Unemployed, looking for PT work    5   2010          0    0       0 |
             44. |                                      [2] Employed PT    5   2011          1    0       0 |
             45. |                                      [2] Employed PT    5   2012          0    0       0 |
             46. |                                      [1] Employed FT    5   2013          1    0       0 |
             47. |                                      [2] Employed PT    5   2014          1    0       1 |
             48. |                                      [2] Employed PT    5   2015          0    0       1 |
             49. |                                      [1] Employed FT    5   2016          1    0       0 |
             50. | [6] Not in the labour force, not marginally attached    5   2017          1    0       0 |
                 |------------------------------------------------------------------------------------------|
             51. |                                      [2] Employed PT    6   2008          0    0       0 |
             52. |                                      [2] Employed PT    6   2009          0    0       0 |
             53. |                                      [2] Employed PT    6   2010          0    0       0 |
             54. |                  [4] Unemployed, looking for PT work    6   2011          1    0       0 |
             55. |                                      [2] Employed PT    6   2012          1    0       0 |
             56. |                  [3] Unemployed, looking for FT work    6   2013          1    0       0 |
             57. | [6] Not in the labour force, not marginally attached    6   2014          1    0       0 |
             58. |     [5] Not in the labour force, marginally attached    6   2015          1    0       0 |
             59. | [6] Not in the labour force, not marginally attached    6   2016          1    0       0 |
             60. | [6] Not in the labour force, not marginally attached    6   2017          0    0       0 |
                 |------------------------------------------------------------------------------------------|
             61. | [6] Not in the labour force, not marginally attached    7   2008          0    1       0 |
             62. | [6] Not in the labour force, not marginally attached    7   2009          0    1       0 |
             63. | [6] Not in the labour force, not marginally attached    7   2010          0    1       0 |
             64. | [6] Not in the labour force, not marginally attached    7   2011          0    1       0 |
             65. | [6] Not in the labour force, not marginally attached    7   2012          0    1       0 |
             66. | [6] Not in the labour force, not marginally attached    7   2013          0    1       0 |
             67. | [6] Not in the labour force, not marginally attached    7   2014          0    1       0 |
             68. | [6] Not in the labour force, not marginally attached    7   2015          0    1       0 |
             69. | [6] Not in the labour force, not marginally attached    7   2016          0    1       0 |
             70. | [6] Not in the labour force, not marginally attached    7   2017          0    1       0 |
                 |------------------------------------------------------------------------------------------|
             71. | [6] Not in the labour force, not marginally attached    8   2008          0    0       0 |
             72. |                                      [1] Employed FT    8   2009          1    0       0 |
             73. |                                      [2] Employed PT    8   2010          1    0       1 |
             74. |                                      [2] Employed PT    8   2011          0    0       1 |
             75. |                                      [2] Employed PT    8   2012          0    0       1 |
             76. |                                      [2] Employed PT    8   2013          0    0       1 |
             77. |     [5] Not in the labour force, marginally attached    8   2014          1    0       0 |
             78. |                  [3] Unemployed, looking for FT work    8   2015          1    0       0 |
             79. |     [5] Not in the labour force, marginally attached    8   2016          1    0       0 |
             80. | [6] Not in the labour force, not marginally attached    8   2017          1    0       0 |
                 |------------------------------------------------------------------------------------------|
             81. |                                      [2] Employed PT    9   2008          0    0       0 |
             82. |                                      [2] Employed PT    9   2009          0    0       0 |
             83. |                                      [1] Employed FT    9   2010          1    0       0 |
             84. |                                      [2] Employed PT    9   2011          1    0       1 |
             85. |                                      [2] Employed PT    9   2012          0    0       1 |
             86. |                                      [2] Employed PT    9   2013          0    0       1 |
             87. |     [5] Not in the labour force, marginally attached    9   2014          1    0       0 |
             88. |     [5] Not in the labour force, marginally attached    9   2015          0    0       0 |
             89. |     [5] Not in the labour force, marginally attached    9   2016          0    0       0 |
             90. |     [5] Not in the labour force, marginally attached    9   2017          0    0       0 |
                 |------------------------------------------------------------------------------------------|
             91. | [6] Not in the labour force, not marginally attached   10   2008          0    0       0 |
             92. | [6] Not in the labour force, not marginally attached   10   2009          0    0       0 |
             93. |     [5] Not in the labour force, marginally attached   10   2010          1    0       0 |
             94. |                                      [2] Employed PT   10   2011          1    0       0 |
             95. |     [5] Not in the labour force, marginally attached   10   2012          1    0       0 |
             96. |                                      [1] Employed FT   10   2013          1    0       0 |
             97. |                                      [1] Employed FT   10   2014          0    0       0 |
             98. |                                      [1] Employed FT   10   2015          0    0       0 |
             99. |                                      [1] Employed FT   10   2016          0    0       0 |
            100. |                                      [1] Employed FT   10   2017          0    0       0 |
                 +------------------------------------------------------------------------------------------+


            Comment


            • #7
              Oh Thank you! This is great and the code works. I'm wondering if you could explain this to me in a little more detail:

              *REPLACE VALUES OF PART TIME AND NO TRANSITION FOLLOWING FULL TIME TO 1 bys id (year): replace FT2PT= FT2PT[_n-1] if esdtl==2 & transition==0 replace FT2PT=0 if missing(FT2PT)
              What is this doing exactly?

              Thanks again

              Comment


              • #8
                and if I wanted to create a variable that indicated FT to FT (e.g. no transition for people in full-time work) would I do the following:

                bys id (year): gen FT2FT= cond(transition==0 & esdtl[_n-1]==1 & esdtl==1, 1, 0)

                Would that be right? Would I need to do anything else?

                Comment


                • #9
                  Oh Thank you! This is great and the code works. I'm wondering if you could explain this to me in a little more detail:

                  *REPLACE VALUES OF PART TIME AND NO TRANSITION FOLLOWING FULL TIME TO 1 bys id (year): replace FT2PT= FT2PT[_n-1] if esdtl==2 & transition==0 replace FT2PT=0 if missing(FT2PT)
                  What is this doing exactly?
                  I will shrink the example for ease of illustration, keeping individuals with id=8 and id=9

                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input byte(losatyh esdtl id) float year
                   5 6 8 2008
                  10 1 8 2009
                  10 2 8 2010
                   9 2 8 2011
                   8 2 8 2012
                   8 2 8 2013
                   5 5 8 2014
                   8 3 8 2015
                   5 5 8 2016
                   1 6 8 2017
                   5 2 9 2008
                   5 2 9 2009
                   7 1 9 2010
                   5 2 9 2011
                   6 2 9 2012
                   6 2 9 2013
                   8 5 9 2014
                   8 5 9 2015
                   8 5 9 2016
                  10 5 9 2017
                  end
                  label values losatyh OLOSATYH
                  label def OLOSATYH 5 "[5] Neither satisfied nor dissatisfied", modify
                  label def OLOSATYH 10 "[10] Totally satisfied", modify
                  label values esdtl OESDTL
                  label def OESDTL 1 "[1] Employed FT", modify
                  label def OESDTL 2 "[2] Employed PT", modify
                  label def OESDTL 3 "[3] Unemployed, looking for FT work", modify
                  label def OESDTL 5 "[5] Not in the labour force, marginally attached", modify
                  label def OESDTL 6 "[6] Not in the labour force, not marginally attached", modify
                  *GENERATE VARIABLE THAT IDENTIFIES ANY KIND OF TRANSITION
                  bys id (year): gen transition = cond( esdtl[_n] !=esdtl[_n-1], 1, 0 )
                  bys id (year): replace transition=0 if _n==1

                  So the command below tags the first observation that follows a transition from full-time to part time (i.e., assigns it a value of 1 and 0 for all other observations)

                  Code:
                  bys id (year): gen FT2PT= cond(transition==1 & esdtl[_n-1]==1 & esdtl==2, 1, 0)
                  
                  
                  
                  . l esdtl id year transition FT2PT, sepby(id)
                  
                       +-------------------------------------------------------------------------------------+
                       |                                                esdtl   id   year   transi~n   FT2PT |
                       |-------------------------------------------------------------------------------------|
                    1. | [6] Not in the labour force, not marginally attached    8   2008          0       0 |
                    2. |                                      [1] Employed FT    8   2009          1       0 |
                    3. |                                      [2] Employed PT    8   2010          1       1 |
                    4. |                                      [2] Employed PT    8   2011          0       0 |
                    5. |                                      [2] Employed PT    8   2012          0       0 |
                    6. |                                      [2] Employed PT    8   2013          0       0 |
                    7. |     [5] Not in the labour force, marginally attached    8   2014          1       0 |
                    8. |                  [3] Unemployed, looking for FT work    8   2015          1       0 |
                    9. |     [5] Not in the labour force, marginally attached    8   2016          1       0 |
                   10. | [6] Not in the labour force, not marginally attached    8   2017          1       0 |
                       |-------------------------------------------------------------------------------------|
                   11. |                                      [2] Employed PT    9   2008          0       0 |
                   12. |                                      [2] Employed PT    9   2009          0       0 |
                   13. |                                      [1] Employed FT    9   2010          1       0 |
                   14. |                                      [2] Employed PT    9   2011          1       1 |
                   15. |                                      [2] Employed PT    9   2012          0       0 |
                   16. |                                      [2] Employed PT    9   2013          0       0 |
                   17. |     [5] Not in the labour force, marginally attached    9   2014          1       0 |
                   18. |     [5] Not in the labour force, marginally attached    9   2015          0       0 |
                   19. |     [5] Not in the labour force, marginally attached    9   2016          0       0 |
                   20. |     [5] Not in the labour force, marginally attached    9   2017          0       0 |
                       +-------------------------------------------------------------------------------------+
                  However, we also want to assign a value of 1 to observations that fall below the tagged observation where status does not change. This can be useful because you may want to investigate whether the length of time spent in a state (for unemployment, also called "spell of unemployment") affects well-being. It may be that there is no significant change in well-being for individuals who transition out of and into employment in the space of a year but not for those who spend a longer period out of employment. This allows you to check this.

                  Code:
                  bys id (year): replace FT2PT= FT2PT[_n-1] if esdtl==2 & transition==0
                  So here, I tell Stata to replace the indicator FT2PT with its value in the row above it FT2PT[_n-1] for each id separately after sorting year in asscending order (bys id (year)) if the state is part-time employment (esdtl==2) and the previous state was part time employment, i.e., no change in state (transition==0). So because the tagged value was 1 when we have a change from FT to PT and because Stata will do this replacement from top to bottom, it will replace the zero values below the tagged value with a value of 1 where this condition holds.


                  Code:
                  . bys id (year): replace FT2PT= FT2PT[_n-1] if esdtl==2 & transition==0
                  (7 real changes made, 2 to missing)
                  
                  . l esdtl id year transition FT2PT, sepby(id)
                  
                       +-------------------------------------------------------------------------------------+
                       |                                                esdtl   id   year   transi~n   FT2PT |
                       |-------------------------------------------------------------------------------------|
                    1. | [6] Not in the labour force, not marginally attached    8   2008          0       0 |
                    2. |                                      [1] Employed FT    8   2009          1       0 |
                    3. |                                      [2] Employed PT    8   2010          1       1 |
                    4. |                                      [2] Employed PT    8   2011          0       1 |
                    5. |                                      [2] Employed PT    8   2012          0       1 |
                    6. |                                      [2] Employed PT    8   2013          0       1 |
                    7. |     [5] Not in the labour force, marginally attached    8   2014          1       0 |
                    8. |                  [3] Unemployed, looking for FT work    8   2015          1       0 |
                    9. |     [5] Not in the labour force, marginally attached    8   2016          1       0 |
                   10. | [6] Not in the labour force, not marginally attached    8   2017          1       0 |
                       |-------------------------------------------------------------------------------------|
                   11. |                                      [2] Employed PT    9   2008          0       . |
                   12. |                                      [2] Employed PT    9   2009          0       . |
                   13. |                                      [1] Employed FT    9   2010          1       0 |
                   14. |                                      [2] Employed PT    9   2011          1       1 |
                   15. |                                      [2] Employed PT    9   2012          0       1 |
                   16. |                                      [2] Employed PT    9   2013          0       1 |
                   17. |     [5] Not in the labour force, marginally attached    9   2014          1       0 |
                   18. |     [5] Not in the labour force, marginally attached    9   2015          0       0 |
                   19. |     [5] Not in the labour force, marginally attached    9   2016          0       0 |
                   20. |     [5] Not in the labour force, marginally attached    9   2017          0       0 |
                       +-------------------------------------------------------------------------------------+
                  The first year of the sample is 2008. So Stata will assign a missing value for 2007 and will also replace the zero values for earlier years with missing values if the condition esdtl==2 & transition==0 holds. I therefore replace these missing values with zeros again.

                  Code:
                  replace FT2PT=0 if missing(FT2PT)
                  Note that this solution is not unique and you can come up with a different approach (maybe even more efficient) that results in the desired outcome, but this was how I approached it.

                  and if I wanted to create a variable that indicated FT to FT (e.g. no transition for people in full-time work) would I do the following:

                  bys id (year): gen FT2FT= cond(transition==0 & esdtl[_n-1]==1 & esdtl==1, 1, 0)

                  Would that be right? Would I need to do anything else?
                  Yes, this will do it for any 2 or more successive years. However, if you want to identify whether an individual did not transition from full time for the whole sample period (and not just any two years)

                  Code:
                  by id: gen NTFT= NT & esdtl==1
                  Last edited by Andrew Musau; 12 Mar 2018, 06:05.

                  Comment


                  • #10
                    Hi Andrew, thanks for your codes in creating transition indicators. I, too, find it very helpful.

                    You mentioned in #6 that
                    An additional note is that it may be best to xtset your data and use time-series operators if you have an unbalanced panel (missing years for some individuals in the panel).
                    Can I please clarify if it is simply a matter of replacing -variable[_n-1]- with -L.variable-. e.g.
                    Code:
                     
                     bys id (year): gen FT2PT= cond(transition==1 & L.esdtl==1 & esdtl==2, 1, 0)
                    or if there are other intricacies one should be aware of?

                    Thanks.

                    Comment


                    • #11
                      Can I please clarify if it is simply a matter of replacing -variable[_n-1]- with -L.variable-. e.g.
                      Yes, that's correct once you have xtset your data

                      Code:
                      xtset id year
                      Because Stata understands the panel structure of your data, no sorting is needed. Therefore,

                      Code:
                      gen FT2PT= cond(transition==1 & L.esdtl==1 & esdtl==2, 1, 0)
                      will suffice.

                      Comment


                      • #12
                        I see. Thanks very much indeed for the explanation.

                        Comment


                        • #13
                          Dear Andrew

                          Many thanks for the syntax - I use it all the time.

                          I wanted to ask how I would go about creating variables that capture transitions into full-time employment or part-time employment and out of the labour force, for example from employment, full-time in 2008 from either part-time or out of the labour force in 2009. I've tried to adapt the code you did earlier but I'm not sure that I've done it properly.

                          Essentially, I just want variables that capture transitions into either FT, PT or OUT from any previous status

                          Can you help?

                          Much appreciated again
                          Brendan

                          Code:
                          * Example generated by -dataex-. To install: ssc install dataex
                          clear
                          input float employment int year
                          2 2002
                          2 2003
                          2 2004
                          2 2003
                          2 2004
                          2 2003
                          1 2004
                          1 2005
                          3 2006
                          1 2007
                          4 2008
                          2 2009
                          2 2010
                          4 2011
                          4 2012
                          4 2013
                          4 2014
                          4 2015
                          4 2016
                          4 2017
                          2 2015
                          4 2016
                          2 2017
                          1 2004
                          1 2005
                          1 2006
                          1 2007
                          1 2008
                          1 2009
                          4 2010
                          4 2011
                          4 2012
                          4 2013
                          4 2014
                          4 2015
                          4 2016
                          1 2007
                          1 2008
                          1 2009
                          1 2010
                          1 2011
                          1 2012
                          1 2013
                          1 2014
                          1 2015
                          1 2016
                          1 2017
                          2 2011
                          2 2012
                          2 2013
                          2 2014
                          2 2015
                          2 2016
                          2 2017
                          1 2007
                          1 2008
                          1 2009
                          1 2010
                          1 2011
                          1 2012
                          1 2013
                          1 2014
                          1 2015
                          1 2016
                          1 2017
                          1 2001
                          1 2002
                          1 2003
                          2 2017
                          1 2016
                          1 2017
                          3 2010
                          1 2011
                          1 2012
                          2 2013
                          2 2014
                          2 2015
                          2 2016
                          2 2017
                          1 2008
                          1 2009
                          1 2010
                          1 2011
                          1 2012
                          1 2013
                          1 2014
                          1 2015
                          1 2016
                          1 2017
                          1 2008
                          1 2009
                          1 2010
                          1 2011
                          1 2012
                          1 2013
                          1 2014
                          1 2015
                          1 2016
                          1 2017
                          4 2012
                          end
                          label values employment employment
                          label def employment 1 "[1] employed, FT", modify
                          label def employment 2 "[2] employed, PT", modify
                          label def employment 3 "[3] out of the labour force", modify

                          Comment


                          • #14
                            Essentially, I just want variables that capture transitions into either FT, PT or OUT from any previous status
                            Code:
                            *GENERATE ID VARIABLE
                            gen id= sum(year[_n-1]>year)
                            *XTSET THE DATA
                            xtset id year
                            *SPECIFY CONDITION
                            bys id: gen wanted= inlist(employment, 1, 2, 3) if employment!=L.employment & _n>1
                            replace wanted=0 if missing(wanted)
                            If you have a missing year, then the lagged value (L.employment) will be missing and therefore the wanted variable will take a value of 1 in the present year. If this is not desired, you can add "&!missing(L.employment)" into the code. Otherwise, if you just want to consider the years present and disregard missing years, revert to

                            Code:
                            bys id (time): gen wanted= inlist(employment, 1, 2, 3) if employment!=employment[_n-1] & _n>1
                            Res.:

                            Code:
                            . l id year employment wanted, sepby(id)
                            
                                 +--------------------------------------------------+
                                 | id   year                    employment   wanted |
                                 |--------------------------------------------------|
                              1. |  1   2002              [2] employed, PT        0 |
                              2. |  1   2003              [2] employed, PT        0 |
                              3. |  1   2004              [2] employed, PT        0 |
                                 |--------------------------------------------------|
                              4. |  2   2003              [2] employed, PT        0 |
                              5. |  2   2004              [2] employed, PT        0 |
                                 |--------------------------------------------------|
                              6. |  3   2003              [2] employed, PT        0 |
                              7. |  3   2004              [1] employed, FT        1 |
                              8. |  3   2005              [1] employed, FT        0 |
                              9. |  3   2006   [3] out of the labour force        1 |
                             10. |  3   2007              [1] employed, FT        1 |
                             11. |  3   2008                             4        0 |
                             12. |  3   2009              [2] employed, PT        1 |
                             13. |  3   2010              [2] employed, PT        0 |
                             14. |  3   2011                             4        0 |
                             15. |  3   2012                             4        0 |
                             16. |  3   2013                             4        0 |
                             17. |  3   2014                             4        0 |
                             18. |  3   2015                             4        0 |
                             19. |  3   2016                             4        0 |
                             20. |  3   2017                             4        0 |
                                 |--------------------------------------------------|
                             21. |  4   2015              [2] employed, PT        0 |
                             22. |  4   2016                             4        0 |
                             23. |  4   2017              [2] employed, PT        1 |
                                 |--------------------------------------------------|
                             24. |  5   2004              [1] employed, FT        0 |
                             25. |  5   2005              [1] employed, FT        0 |
                             26. |  5   2006              [1] employed, FT        0 |
                             27. |  5   2007              [1] employed, FT        0 |
                             28. |  5   2008              [1] employed, FT        0 |
                             29. |  5   2009              [1] employed, FT        0 |
                             30. |  5   2010                             4        0 |
                             31. |  5   2011                             4        0 |
                             32. |  5   2012                             4        0 |
                             33. |  5   2013                             4        0 |
                             34. |  5   2014                             4        0 |
                             35. |  5   2015                             4        0 |
                             36. |  5   2016                             4        0 |
                                 |--------------------------------------------------|
                             37. |  6   2007              [1] employed, FT        0 |
                             38. |  6   2008              [1] employed, FT        0 |
                             39. |  6   2009              [1] employed, FT        0 |
                             40. |  6   2010              [1] employed, FT        0 |
                             41. |  6   2011              [1] employed, FT        0 |
                             42. |  6   2012              [1] employed, FT        0 |
                             43. |  6   2013              [1] employed, FT        0 |
                             44. |  6   2014              [1] employed, FT        0 |
                             45. |  6   2015              [1] employed, FT        0 |
                             46. |  6   2016              [1] employed, FT        0 |
                             47. |  6   2017              [1] employed, FT        0 |
                                 |--------------------------------------------------|
                             48. |  7   2011              [2] employed, PT        0 |
                             49. |  7   2012              [2] employed, PT        0 |
                             50. |  7   2013              [2] employed, PT        0 |
                             51. |  7   2014              [2] employed, PT        0 |
                             52. |  7   2015              [2] employed, PT        0 |
                             53. |  7   2016              [2] employed, PT        0 |
                             54. |  7   2017              [2] employed, PT        0 |
                                 |--------------------------------------------------|
                             55. |  8   2007              [1] employed, FT        0 |
                             56. |  8   2008              [1] employed, FT        0 |
                             57. |  8   2009              [1] employed, FT        0 |
                             58. |  8   2010              [1] employed, FT        0 |
                             59. |  8   2011              [1] employed, FT        0 |
                             60. |  8   2012              [1] employed, FT        0 |
                             61. |  8   2013              [1] employed, FT        0 |
                             62. |  8   2014              [1] employed, FT        0 |
                             63. |  8   2015              [1] employed, FT        0 |
                             64. |  8   2016              [1] employed, FT        0 |
                             65. |  8   2017              [1] employed, FT        0 |
                                 |--------------------------------------------------|
                             66. |  9   2001              [1] employed, FT        0 |
                             67. |  9   2002              [1] employed, FT        0 |
                             68. |  9   2003              [1] employed, FT        0 |
                             69. |  9   2017              [2] employed, PT        1 |
                                 |--------------------------------------------------|
                             70. | 10   2016              [1] employed, FT        0 |
                             71. | 10   2017              [1] employed, FT        0 |
                                 |--------------------------------------------------|
                             72. | 11   2010   [3] out of the labour force        0 |
                             73. | 11   2011              [1] employed, FT        1 |
                             74. | 11   2012              [1] employed, FT        0 |
                             75. | 11   2013              [2] employed, PT        1 |
                             76. | 11   2014              [2] employed, PT        0 |
                             77. | 11   2015              [2] employed, PT        0 |
                             78. | 11   2016              [2] employed, PT        0 |
                             79. | 11   2017              [2] employed, PT        0 |
                                 |--------------------------------------------------|
                             80. | 12   2008              [1] employed, FT        0 |
                             81. | 12   2009              [1] employed, FT        0 |
                             82. | 12   2010              [1] employed, FT        0 |
                             83. | 12   2011              [1] employed, FT        0 |
                             84. | 12   2012              [1] employed, FT        0 |
                             85. | 12   2013              [1] employed, FT        0 |
                             86. | 12   2014              [1] employed, FT        0 |
                             87. | 12   2015              [1] employed, FT        0 |
                             88. | 12   2016              [1] employed, FT        0 |
                             89. | 12   2017              [1] employed, FT        0 |
                                 |--------------------------------------------------|
                             90. | 13   2008              [1] employed, FT        0 |
                             91. | 13   2009              [1] employed, FT        0 |
                             92. | 13   2010              [1] employed, FT        0 |
                             93. | 13   2011              [1] employed, FT        0 |
                             94. | 13   2012              [1] employed, FT        0 |
                             95. | 13   2013              [1] employed, FT        0 |
                             96. | 13   2014              [1] employed, FT        0 |
                             97. | 13   2015              [1] employed, FT        0 |
                             98. | 13   2016              [1] employed, FT        0 |
                             99. | 13   2017              [1] employed, FT        0 |
                                 |--------------------------------------------------|
                            100. | 14   2012                             4        0 |
                                 +--------------------------------------------------+

                            Comment


                            • #15
                              Thanks Andrew - most helpful

                              and if I wanted to do it separately for each outcome, e.g. FT and PT > OUT or PT and OUT > FT in the next year, how would I do that?

                              Thanks

                              Brendan

                              Comment

                              Working...
                              X