Announcement

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

  • #16
    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.
    Also, you mentioned in #9 about investigating length of time in a state or between transitions (e.g. time out of the labour force) - how would I, for example calculate the spells between one state and another into a kind of continuous variable?

    Best
    Brendan

    Comment


    • #17

      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?
      If you want to consider a transition into one state only, e.g., into full time employment, then change
      Code:
      inlist(employment, 1, 2, 3)
      to

      Code:
      inlist(employment, 1)
      in #14. This will give you transition from any state to full-time employment. The same for any state to part-time

      Code:
      inlist(employment, 2)
      and so on.

      Also, you mentioned in #9 about investigating length of time in a state or between transitions (e.g. time out of the labour force) - how would I, for example calculate the spells between one state and another into a kind of continuous variable?
      Taking your initial data example, after creating the transition variable, you can create a variable that measures the duration in a particular state in the following way

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input byte(losatyh esdtl id) float(year transition)
       5 6  1 2008 0
       6 2  1 2009 1
       5 2  1 2010 0
       6 2  1 2011 0
       4 2  1 2012 0
       4 2  1 2013 0
       5 2  1 2014 0
       8 2  1 2015 0
       8 2  1 2016 0
       8 2  1 2017 0
       7 2  2 2008 0
       8 1  2 2009 1
       6 1  2 2010 0
       7 3  2 2011 1
       6 1  2 2012 1
       8 5  2 2013 1
       7 2  2 2014 1
       8 2  2 2015 0
       4 6  2 2016 1
       5 5  2 2017 1
       2 6  3 2008 0
       5 6  3 2009 0
       5 6  3 2010 0
      10 2  3 2011 1
       8 2  3 2012 0
       9 2  3 2013 0
       8 2  3 2014 0
      10 2  3 2015 0
       8 2  3 2016 0
       8 2  3 2017 0
       8 2  4 2008 0
       8 2  4 2009 0
       8 6  4 2010 1
       8 5  4 2011 1
       7 6  4 2012 1
       7 5  4 2013 1
       7 3  4 2014 1
       6 4  4 2015 1
       8 3  4 2016 1
       7 5  4 2017 1
       7 2  5 2008 0
       8 4  5 2009 1
       7 4  5 2010 0
       7 2  5 2011 1
       6 2  5 2012 0
       8 1  5 2013 1
       7 2  5 2014 1
       5 2  5 2015 0
       7 1  5 2016 1
       7 6  5 2017 1
       4 2  6 2008 0
       5 2  6 2009 0
       7 2  6 2010 0
      10 4  6 2011 1
      10 2  6 2012 1
       9 3  6 2013 1
      10 6  6 2014 1
      10 5  6 2015 1
       6 6  6 2016 1
       5 6  6 2017 0
       5 6  7 2008 0
       6 6  7 2009 0
       8 6  7 2010 0
       7 6  7 2011 0
       5 6  7 2012 0
       2 6  7 2013 0
       2 6  7 2014 0
       1 6  7 2015 0
       3 6  7 2016 0
       1 6  7 2017 0
       5 6  8 2008 0
      10 1  8 2009 1
      10 2  8 2010 1
       9 2  8 2011 0
       8 2  8 2012 0
       8 2  8 2013 0
       5 5  8 2014 1
       8 3  8 2015 1
       5 5  8 2016 1
       1 6  8 2017 1
       5 2  9 2008 0
       5 2  9 2009 0
       7 1  9 2010 1
       5 2  9 2011 1
       6 2  9 2012 0
       6 2  9 2013 0
       8 5  9 2014 1
       8 5  9 2015 0
       8 5  9 2016 0
      10 5  9 2017 0
       6 6 10 2008 0
       7 6 10 2009 0
       7 5 10 2010 1
       4 2 10 2011 1
       6 5 10 2012 1
       5 1 10 2013 1
       6 1 10 2014 0
       7 1 10 2015 0
       7 1 10 2016 0
       7 1 10 2017 0
      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
      
      gen group= sum(transition) if transition==1
      replace group=group[_n-1] if missing(group) & _n>1
      replace group=0 if missing(group)
      bys id group (year): egen duration= count(group)
      It is not clear what you should do if you have missing years as you do not know whether there was any transition during these years. Therefore, this assumes a balanced panel.

      Res.:

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

      Comment


      • #18
        Thanks Andrew Musau, this code has been invaluable to my work. I do have a question about it.

        How would I just make a variable that captures years since transition, not just a count of years in the transition status as below:

        Code:
         
         gen group= sum(transition) if transition==1 replace group=group[_n-1] if missing(group) & _n>1 replace group=0 if missing(group) bys id group (year): egen duration= count(group)
        But one that counts every year/wave since transition. So if an ID had was in the sample for 9 years after initial transition, each year would be counted 1, 2, 3, 4, 5, 6.... at each wave

        Any help would be most appreciated

        best
        Brendan

        Comment


        • #19
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input byte(losatyh esdtl id) float(year transition group duration)
           5 6  1 2008 0  0  1
           6 2  1 2009 1  1  9
           5 2  1 2010 0  1  9
           6 2  1 2011 0  1  9
           4 2  1 2012 0  1  9
           4 2  1 2013 0  1  9
           5 2  1 2014 0  1  9
           8 2  1 2015 0  1  9
           8 2  1 2016 0  1  9
           8 2  1 2017 0  1  9
           7 2  2 2008 0  1  1
           8 1  2 2009 1  2  2
           6 1  2 2010 0  2  2
           7 3  2 2011 1  3  1
           6 1  2 2012 1  4  1
           8 5  2 2013 1  5  1
           7 2  2 2014 1  6  2
           8 2  2 2015 0  6  2
           4 6  2 2016 1  7  1
           5 5  2 2017 1  8  1
           2 6  3 2008 0  8  3
           5 6  3 2009 0  8  3
           5 6  3 2010 0  8  3
          10 2  3 2011 1  9  7
           8 2  3 2012 0  9  7
           9 2  3 2013 0  9  7
           8 2  3 2014 0  9  7
          10 2  3 2015 0  9  7
           8 2  3 2016 0  9  7
           8 2  3 2017 0  9  7
           8 2  4 2008 0  9  2
           8 2  4 2009 0  9  2
           8 6  4 2010 1 10  1
           8 5  4 2011 1 11  1
           7 6  4 2012 1 12  1
           7 5  4 2013 1 13  1
           7 3  4 2014 1 14  1
           6 4  4 2015 1 15  1
           8 3  4 2016 1 16  1
           7 5  4 2017 1 17  1
           7 2  5 2008 0 17  1
           8 4  5 2009 1 18  2
           7 4  5 2010 0 18  2
           7 2  5 2011 1 19  2
           6 2  5 2012 0 19  2
           8 1  5 2013 1 20  1
           7 2  5 2014 1 21  2
           5 2  5 2015 0 21  2
           7 1  5 2016 1 22  1
           7 6  5 2017 1 23  1
           4 2  6 2008 0 23  3
           5 2  6 2009 0 23  3
           7 2  6 2010 0 23  3
          10 4  6 2011 1 24  1
          10 2  6 2012 1 25  1
           9 3  6 2013 1 26  1
          10 6  6 2014 1 27  1
          10 5  6 2015 1 28  1
           6 6  6 2016 1 29  2
           5 6  6 2017 0 29  2
           5 6  7 2008 0 29 10
           6 6  7 2009 0 29 10
           8 6  7 2010 0 29 10
           7 6  7 2011 0 29 10
           5 6  7 2012 0 29 10
           2 6  7 2013 0 29 10
           2 6  7 2014 0 29 10
           1 6  7 2015 0 29 10
           3 6  7 2016 0 29 10
           1 6  7 2017 0 29 10
           5 6  8 2008 0 29  1
          10 1  8 2009 1 30  1
          10 2  8 2010 1 31  4
           9 2  8 2011 0 31  4
           8 2  8 2012 0 31  4
           8 2  8 2013 0 31  4
           5 5  8 2014 1 32  1
           8 3  8 2015 1 33  1
           5 5  8 2016 1 34  1
           1 6  8 2017 1 35  1
           5 2  9 2008 0 35  2
           5 2  9 2009 0 35  2
           7 1  9 2010 1 36  1
           5 2  9 2011 1 37  3
           6 2  9 2012 0 37  3
           6 2  9 2013 0 37  3
           8 5  9 2014 1 38  4
           8 5  9 2015 0 38  4
           8 5  9 2016 0 38  4
          10 5  9 2017 0 38  4
           6 6 10 2008 0 38  2
           7 6 10 2009 0 38  2
           7 5 10 2010 1 39  1
           4 2 10 2011 1 40  1
           6 5 10 2012 1 41  1
           5 1 10 2013 1 42  5
           6 1 10 2014 0 42  5
           7 1 10 2015 0 42  5
           7 1 10 2016 0 42  5
           7 1 10 2017 0 42  5
          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
          
          bys id group (year): gen yearsince= year-year[1] if transition[1] & _N>1
          Res.:

          Code:
          . l id- yearsince , sepby(id)
          
               +----------------------------------------------------+
               | id   year   transi~n   group   duration   yearsi~e |
               |----------------------------------------------------|
            1. |  1   2008          0       0          1          . |
            2. |  1   2009          1       1          9          0 |
            3. |  1   2010          0       1          9          1 |
            4. |  1   2011          0       1          9          2 |
            5. |  1   2012          0       1          9          3 |
            6. |  1   2013          0       1          9          4 |
            7. |  1   2014          0       1          9          5 |
            8. |  1   2015          0       1          9          6 |
            9. |  1   2016          0       1          9          7 |
           10. |  1   2017          0       1          9          8 |
               |----------------------------------------------------|
           11. |  2   2008          0       1          1          . |
           12. |  2   2009          1       2          2          0 |
           13. |  2   2010          0       2          2          1 |
           14. |  2   2011          1       3          1          . |
           15. |  2   2012          1       4          1          . |
           16. |  2   2013          1       5          1          . |
           17. |  2   2014          1       6          2          0 |
           18. |  2   2015          0       6          2          1 |
           19. |  2   2016          1       7          1          . |
           20. |  2   2017          1       8          1          . |
               |----------------------------------------------------|
           21. |  3   2008          0       8          3          . |
           22. |  3   2009          0       8          3          . |
           23. |  3   2010          0       8          3          . |
           24. |  3   2011          1       9          7          0 |
           25. |  3   2012          0       9          7          1 |
           26. |  3   2013          0       9          7          2 |
           27. |  3   2014          0       9          7          3 |
           28. |  3   2015          0       9          7          4 |
           29. |  3   2016          0       9          7          5 |
           30. |  3   2017          0       9          7          6 |
               |----------------------------------------------------|
           31. |  4   2008          0       9          2          . |
           32. |  4   2009          0       9          2          . |
           33. |  4   2010          1      10          1          . |
           34. |  4   2011          1      11          1          . |
           35. |  4   2012          1      12          1          . |
           36. |  4   2013          1      13          1          . |
           37. |  4   2014          1      14          1          . |
           38. |  4   2015          1      15          1          . |
           39. |  4   2016          1      16          1          . |
           40. |  4   2017          1      17          1          . |
               |----------------------------------------------------|
           41. |  5   2008          0      17          1          . |
           42. |  5   2009          1      18          2          0 |
           43. |  5   2010          0      18          2          1 |
           44. |  5   2011          1      19          2          0 |
           45. |  5   2012          0      19          2          1 |
           46. |  5   2013          1      20          1          . |
           47. |  5   2014          1      21          2          0 |
           48. |  5   2015          0      21          2          1 |
           49. |  5   2016          1      22          1          . |
           50. |  5   2017          1      23          1          . |
               |----------------------------------------------------|
           51. |  6   2008          0      23          3          . |
           52. |  6   2009          0      23          3          . |
           53. |  6   2010          0      23          3          . |
           54. |  6   2011          1      24          1          . |
           55. |  6   2012          1      25          1          . |
           56. |  6   2013          1      26          1          . |
           57. |  6   2014          1      27          1          . |
           58. |  6   2015          1      28          1          . |
           59. |  6   2016          1      29          2          0 |
           60. |  6   2017          0      29          2          1 |
               |----------------------------------------------------|
           61. |  7   2008          0      29         10          . |
           62. |  7   2009          0      29         10          . |
           63. |  7   2010          0      29         10          . |
           64. |  7   2011          0      29         10          . |
           65. |  7   2012          0      29         10          . |
           66. |  7   2013          0      29         10          . |
           67. |  7   2014          0      29         10          . |
           68. |  7   2015          0      29         10          . |
           69. |  7   2016          0      29         10          . |
           70. |  7   2017          0      29         10          . |
               |----------------------------------------------------|
           71. |  8   2008          0      29          1          . |
           72. |  8   2009          1      30          1          . |
           73. |  8   2010          1      31          4          0 |
           74. |  8   2011          0      31          4          1 |
           75. |  8   2012          0      31          4          2 |
           76. |  8   2013          0      31          4          3 |
           77. |  8   2014          1      32          1          . |
           78. |  8   2015          1      33          1          . |
           79. |  8   2016          1      34          1          . |
           80. |  8   2017          1      35          1          . |
               |----------------------------------------------------|
           81. |  9   2008          0      35          2          . |
           82. |  9   2009          0      35          2          . |
           83. |  9   2010          1      36          1          . |
           84. |  9   2011          1      37          3          0 |
           85. |  9   2012          0      37          3          1 |
           86. |  9   2013          0      37          3          2 |
           87. |  9   2014          1      38          4          0 |
           88. |  9   2015          0      38          4          1 |
           89. |  9   2016          0      38          4          2 |
           90. |  9   2017          0      38          4          3 |
               |----------------------------------------------------|
           91. | 10   2008          0      38          2          . |
           92. | 10   2009          0      38          2          . |
           93. | 10   2010          1      39          1          . |
           94. | 10   2011          1      40          1          . |
           95. | 10   2012          1      41          1          . |
           96. | 10   2013          1      42          5          0 |
           97. | 10   2014          0      42          5          1 |
           98. | 10   2015          0      42          5          2 |
           99. | 10   2016          0      42          5          3 |
          100. | 10   2017          0      42          5          4 |
               +----------------------------------------------------+
          
          .
          Last edited by Andrew Musau; 26 Feb 2022, 08:28.

          Comment


          • #20
            Thanks Andrew Musau, most helpful. One more can you augment the variable to include years BEFORE the transition too?
            best
            Brendan

            Comment


            • #21
              You have several transitions. How do you propose to do that? Show your intended results using a data example, e.g., #19.

              Comment

              Working...
              X