Announcement

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

  • generating change variables in panel-structure

    Dear all,
    I would like check whether I can overwrite the missing deprivation variable (dep) with the value of the previous year. To check whether that does not create a bias I wanted to generate 2 change variables (1 for dep and 1 for income_cat) and compare the two. Deprivation is a dummy and income_cat is categorized like this:

    gen income_cat = .
    replace income_cat = 5 if equivincome > median_inc*1.5 /*wohlhabende*/
    replace income_cat = 4 if equivincome > median_inc & equivincome <= median_inc*1.5 /*höhere mittlere Eink*/
    replace income_cat = 3 if equivincome > median_inc*0.8 & equivincome <= median_inc /*mittlere Eink*/
    replace income_cat = 2 if equivincome > median_inc*0.6 & equivincome <=median_inc*0.8 /*prekäre Einkommen */
    replace income_cat = 1 if equivincome < median_inc*0.6


    Since I am not very advanced in Stata, I tried it with the following code for the age span 2001 to 2003 for deprivation, but the 3rd variable saved 0 changes...:

    gen dep_2001 = .
    replace dep_2001 = 0 if dep == 0 & syear == 2001
    replace dep_2001 = 1 if dep == 1 & syear == 2001

    gen dep_2003 = .
    replace dep_2003 = 0 if dep == 0 & syear == 2003
    replace dep_2003 = 1 if dep == 1 & syear == 2003

    gen dep_0103 = .
    replace dep_0103 = 0 if dep_2001 == 0 & dep_2003 == 0
    replace dep_0103 = 1 if dep_2001 == 0 & dep_2003 == 1
    replace dep_0103 = 2 if dep_2001 == 1 & dep_2003 == 0
    replace dep_0103 = 3 if dep_2001 == 1 & dep_2003 == 1


    This is the Code (I would also consider going a percentage change of equiv income)


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long pid int syear float(dep income_cat equivincome)
     201 2000 . 1      8510
     201 2001 0 1      8858
     201 2002 . 1      1627
     201 2003 0 1      7287
     201 2004 . 3     15185
     201 2005 0 1      7648
     201 2006 . 1      7723
     201 2007 1 2     11488
     201 2008 . 1      8673
     203 2000 . 4     21212
     203 2001 0 4     21281
     203 2002 . 4     25398
     203 2003 0 4     27242
     203 2004 . 4     26525
     203 2005 0 4     18800
     203 2006 . 4     24796
     203 2007 0 4     23217
     203 2008 . 4     23828
     601 2000 . 5  91799.43
     601 2001 0 5  74910.89
     601 2002 . 5  93241.23
     601 2003 0 5  54433.08
     602 2000 . 4     20017
     602 2001 0 4     23594
     602 2002 . 4   23485.5
     602 2003 0 4     22628
     602 2004 . 4     21356
     602 2005 0 4   23876.5
     602 2006 . 5     28357
     602 2007 0 4     24080
     602 2008 . 4   22833.5
     602 2009 . 4     23930
     602 2010 . 4     28200
     602 2011 0 4  25488.86
     602 2012 . 4  21948.55
     604 2007 0 4     24080
     604 2008 . 4   22833.5
     604 2009 . 4     23930
     901 2000 . 3     14350
     901 2001 1 3     14639
     901 2002 . 2     13826
     901 2003 0 2     12504
     901 2004 . 2     14333
     901 2005 1 3     15005
     901 2006 . 3     15071
     901 2007 0 2     14646
     901 2008 . 2     12071
     901 2009 . 2     15222
     901 2010 . 2     15304
     901 2011 0 2     15318
     901 2012 . 2     15066
     901 2013 0 2     15286
     901 2014 . 2     15391
     901 2015 0 2     15355
    1202 2000 . 4     18975
    1202 2001 0 4     17747
    1202 2002 . 4     18806
    1501 2000 . 5     55871
    1501 2001 0 5     61132
    1501 2002 . 5     65084
    1501 2003 0 5     54261
    1501 2004 . 5     44876
    1501 2005 0 5     57810
    1501 2006 . 5     58957
    1501 2007 0 5     57192
    1501 2008 . 5     60712
    1501 2009 . 5     50571
    1501 2010 . 5     50612
    1501 2011 0 5     59658
    1501 2012 . 5    120497
    1501 2013 0 5     54516
    1501 2014 . 5     58659
    1501 2015 0 5     58773
    1501 2016 0 5     55184
    1601 2000 . 1      9079
    1601 2001 0 1  6803.496
    1601 2002 . 3  14995.52
    1601 2003 1 2  11436.73
    1601 2004 . 2 14175.104
    1601 2005 0 2  12105.88
    1601 2006 . 2 14666.102
    1601 2007 1 2 14785.604
    1601 2008 . 3 15809.494
    1601 2009 . 2  14444.07
    1601 2010 . 2 13095.618
    1602 2001 0 1  6803.496
    1602 2002 . 3  14995.52
    1602 2003 1 2  11436.73
    1602 2004 . 2 14175.104
    1602 2005 0 2  12105.88
    1602 2006 . 2 14666.102
    1602 2007 1 2 14785.604
    1602 2008 . 3 15809.494
    1602 2009 . 2  14444.07
    1603 2003 1 2  11436.73
    1603 2004 . 2 14175.104
    1603 2005 0 2  12105.88
    1701 2000 . 5  25680.54
    1701 2001 0 4 25965.174
    1701 2002 . 5 27537.877
    end


    Any assistance will be immensely appreciated


  • #2
    Your initial explanation is clearer.

    I am currently working on my master thesis with Paneldata from the German Socioeconomic Panel and have a problem regarding the created dummy variable: deprivation.
    Since deprivation-variables are from 2001 on and only available every second year I want to fill the missing years with the values of the previous year (which I know how to do).
    In order to do so I wanted to check, whether the income (5 categories in relation to median equivincome) of a person changes in the missing year, where I just filled in the value to make sure there wont be a bias. Therefore I want to create a change variable for deprivation and income (t to t+2; e.g. 2001 to 2003) and compare the two. I am only familiar with basic gen, recode and egen-commands and haven't found anything in the forum, probably because I am not really sure what I am looking for... can anyone help me?
    Otherwise, I couldn't for the life of me figure out what you were asking. Here, I do it all in one.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long pid int syear float(dep income_cat equivincome)
     201 2000 . 1      8510
     201 2001 0 1      8858
     201 2002 . 1      1627
     201 2003 0 1      7287
     201 2004 . 3     15185
     201 2005 0 1      7648
     201 2006 . 1      7723
     201 2007 1 2     11488
     201 2008 . 1      8673
     203 2000 . 4     21212
     203 2001 0 4     21281
     203 2002 . 4     25398
     203 2003 0 4     27242
     203 2004 . 4     26525
     203 2005 0 4     18800
     203 2006 . 4     24796
     203 2007 0 4     23217
     203 2008 . 4     23828
     601 2000 . 5  91799.43
     601 2001 0 5  74910.89
     601 2002 . 5  93241.23
     601 2003 0 5  54433.08
     602 2000 . 4     20017
     602 2001 0 4     23594
     602 2002 . 4   23485.5
     602 2003 0 4     22628
     602 2004 . 4     21356
     602 2005 0 4   23876.5
     602 2006 . 5     28357
     602 2007 0 4     24080
     602 2008 . 4   22833.5
     602 2009 . 4     23930
     602 2010 . 4     28200
     602 2011 0 4  25488.86
     602 2012 . 4  21948.55
     604 2007 0 4     24080
     604 2008 . 4   22833.5
     604 2009 . 4     23930
     901 2000 . 3     14350
     901 2001 1 3     14639
     901 2002 . 2     13826
     901 2003 0 2     12504
     901 2004 . 2     14333
     901 2005 1 3     15005
     901 2006 . 3     15071
     901 2007 0 2     14646
     901 2008 . 2     12071
     901 2009 . 2     15222
     901 2010 . 2     15304
     901 2011 0 2     15318
     901 2012 . 2     15066
     901 2013 0 2     15286
     901 2014 . 2     15391
     901 2015 0 2     15355
    1202 2000 . 4     18975
    1202 2001 0 4     17747
    1202 2002 . 4     18806
    1501 2000 . 5     55871
    1501 2001 0 5     61132
    1501 2002 . 5     65084
    1501 2003 0 5     54261
    1501 2004 . 5     44876
    1501 2005 0 5     57810
    1501 2006 . 5     58957
    1501 2007 0 5     57192
    1501 2008 . 5     60712
    1501 2009 . 5     50571
    1501 2010 . 5     50612
    1501 2011 0 5     59658
    1501 2012 . 5    120497
    1501 2013 0 5     54516
    1501 2014 . 5     58659
    1501 2015 0 5     58773
    1501 2016 0 5     55184
    1601 2000 . 1      9079
    1601 2001 0 1  6803.496
    1601 2002 . 3  14995.52
    1601 2003 1 2  11436.73
    1601 2004 . 2 14175.104
    1601 2005 0 2  12105.88
    1601 2006 . 2 14666.102
    1601 2007 1 2 14785.604
    1601 2008 . 3 15809.494
    1601 2009 . 2  14444.07
    1601 2010 . 2 13095.618
    1602 2001 0 1  6803.496
    1602 2002 . 3  14995.52
    1602 2003 1 2  11436.73
    1602 2004 . 2 14175.104
    1602 2005 0 2  12105.88
    1602 2006 . 2 14666.102
    1602 2007 1 2 14785.604
    1602 2008 . 3 15809.494
    1602 2009 . 2  14444.07
    1603 2003 1 2  11436.73
    1603 2004 . 2 14175.104
    1603 2005 0 2  12105.88
    1701 2000 . 5  25680.54
    1701 2001 0 4 25965.174
    1701 2002 . 5 27537.877
    end
    
    xtset pid syear
    gen dep2= cond(missing(dep), l.dep, dep)
    gen change= missing(dep) & l.income_cat==income_cat
    label define change 1 "No change" 0 "has changed"
    replace change=. if !missing(dep)
    bys pid (syear): replace change =. if _n==1
    label values change change

    Result:

    Code:
    . l, sepby(pid)
    
         +---------------------------------------------------------------+
         |  pid   syear   dep   income~t   equivi~e   dep2        change |
         |---------------------------------------------------------------|
      1. |  201    2000     .          1       8510      .             . |
      2. |  201    2001     0          1       8858      0             . |
      3. |  201    2002     .          1       1627      0     No change |
      4. |  201    2003     0          1       7287      0             . |
      5. |  201    2004     .          3      15185      0   has changed |
      6. |  201    2005     0          1       7648      0             . |
      7. |  201    2006     .          1       7723      0     No change |
      8. |  201    2007     1          2      11488      1             . |
      9. |  201    2008     .          1       8673      1   has changed |
         |---------------------------------------------------------------|
     10. |  203    2000     .          4      21212      .             . |
     11. |  203    2001     0          4      21281      0             . |
     12. |  203    2002     .          4      25398      0     No change |
     13. |  203    2003     0          4      27242      0             . |
     14. |  203    2004     .          4      26525      0     No change |
     15. |  203    2005     0          4      18800      0             . |
     16. |  203    2006     .          4      24796      0     No change |
     17. |  203    2007     0          4      23217      0             . |
     18. |  203    2008     .          4      23828      0     No change |
         |---------------------------------------------------------------|
     19. |  601    2000     .          5   91799.43      .             . |
     20. |  601    2001     0          5   74910.89      0             . |
     21. |  601    2002     .          5   93241.23      0     No change |
     22. |  601    2003     0          5   54433.08      0             . |
         |---------------------------------------------------------------|
     23. |  602    2000     .          4      20017      .             . |
     24. |  602    2001     0          4      23594      0             . |
     25. |  602    2002     .          4    23485.5      0     No change |
     26. |  602    2003     0          4      22628      0             . |
     27. |  602    2004     .          4      21356      0     No change |
     28. |  602    2005     0          4    23876.5      0             . |
     29. |  602    2006     .          5      28357      0   has changed |
     30. |  602    2007     0          4      24080      0             . |
     31. |  602    2008     .          4    22833.5      0     No change |
     32. |  602    2009     .          4      23930      .     No change |
     33. |  602    2010     .          4      28200      .     No change |
     34. |  602    2011     0          4   25488.86      0             . |
     35. |  602    2012     .          4   21948.55      0     No change |
         |---------------------------------------------------------------|
     36. |  604    2007     0          4      24080      0             . |
     37. |  604    2008     .          4    22833.5      0     No change |
     38. |  604    2009     .          4      23930      .     No change |
         |---------------------------------------------------------------|
     39. |  901    2000     .          3      14350      .             . |
     40. |  901    2001     1          3      14639      1             . |
     41. |  901    2002     .          2      13826      1   has changed |
     42. |  901    2003     0          2      12504      0             . |
     43. |  901    2004     .          2      14333      0     No change |
     44. |  901    2005     1          3      15005      1             . |
     45. |  901    2006     .          3      15071      1     No change |
     46. |  901    2007     0          2      14646      0             . |
     47. |  901    2008     .          2      12071      0     No change |
     48. |  901    2009     .          2      15222      .     No change |
     49. |  901    2010     .          2      15304      .     No change |
     50. |  901    2011     0          2      15318      0             . |
     51. |  901    2012     .          2      15066      0     No change |
     52. |  901    2013     0          2      15286      0             . |
     53. |  901    2014     .          2      15391      0     No change |
     54. |  901    2015     0          2      15355      0             . |
         |---------------------------------------------------------------|
     55. | 1202    2000     .          4      18975      .             . |
     56. | 1202    2001     0          4      17747      0             . |
     57. | 1202    2002     .          4      18806      0     No change |
         |---------------------------------------------------------------|
     58. | 1501    2000     .          5      55871      .             . |
     59. | 1501    2001     0          5      61132      0             . |
     60. | 1501    2002     .          5      65084      0     No change |
     61. | 1501    2003     0          5      54261      0             . |
     62. | 1501    2004     .          5      44876      0     No change |
     63. | 1501    2005     0          5      57810      0             . |
     64. | 1501    2006     .          5      58957      0     No change |
     65. | 1501    2007     0          5      57192      0             . |
     66. | 1501    2008     .          5      60712      0     No change |
     67. | 1501    2009     .          5      50571      .     No change |
     68. | 1501    2010     .          5      50612      .     No change |
     69. | 1501    2011     0          5      59658      0             . |
     70. | 1501    2012     .          5     120497      0     No change |
     71. | 1501    2013     0          5      54516      0             . |
     72. | 1501    2014     .          5      58659      0     No change |
     73. | 1501    2015     0          5      58773      0             . |
     74. | 1501    2016     0          5      55184      0             . |
         |---------------------------------------------------------------|
     75. | 1601    2000     .          1       9079      .             . |
     76. | 1601    2001     0          1   6803.496      0             . |
     77. | 1601    2002     .          3   14995.52      0   has changed |
     78. | 1601    2003     1          2   11436.73      1             . |
     79. | 1601    2004     .          2    14175.1      1     No change |
     80. | 1601    2005     0          2   12105.88      0             . |
     81. | 1601    2006     .          2    14666.1      0     No change |
     82. | 1601    2007     1          2    14785.6      1             . |
     83. | 1601    2008     .          3   15809.49      1   has changed |
     84. | 1601    2009     .          2   14444.07      .   has changed |
     85. | 1601    2010     .          2   13095.62      .     No change |
         |---------------------------------------------------------------|
     86. | 1602    2001     0          1   6803.496      0             . |
     87. | 1602    2002     .          3   14995.52      0   has changed |
     88. | 1602    2003     1          2   11436.73      1             . |
     89. | 1602    2004     .          2    14175.1      1     No change |
     90. | 1602    2005     0          2   12105.88      0             . |
     91. | 1602    2006     .          2    14666.1      0     No change |
     92. | 1602    2007     1          2    14785.6      1             . |
     93. | 1602    2008     .          3   15809.49      1   has changed |
     94. | 1602    2009     .          2   14444.07      .   has changed |
         |---------------------------------------------------------------|
     95. | 1603    2003     1          2   11436.73      1             . |
     96. | 1603    2004     .          2    14175.1      1     No change |
     97. | 1603    2005     0          2   12105.88      0             . |
         |---------------------------------------------------------------|
     98. | 1701    2000     .          5   25680.54      .             . |
     99. | 1701    2001     0          4   25965.17      0             . |
    100. | 1701    2002     .          5   27537.88      0   has changed |
         +---------------------------------------------------------------+
    Last edited by Andrew Musau; 20 Feb 2019, 15:37.

    Comment

    Working...
    X