Announcement

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

  • issue when converting from panel to pooled cross sectional

    Dear STATA users,

    My main database contains longitudinal year-based information between some years (e.g., 2007-2013), and I am taking the ISEI (occupational status score, continuous variable) level as a dependent variable.
    Since not all individuals took part in all the years, I am not interested in a panel analysis, so instead I opted for a pooled cross sectional analysis. But for this, I don't want to choose one particular year so I can avoid any time-variance, and rather work with the moment an individual reached the maximum level of ISEI.
    So my question is: is there any way to tell STATA to keep the observations in the same row when the maximum level of the dependent variable was reached and when this first happened to the individual?
    Here is a visual example:

    ID year ISEI IV1 IV2
    1 1 2008 35 0 ..
    2 1 2009 40 1
    3 1 2011 55 1
    4 1 2012 60 1
    5 2 2010 55 0
    6 2 2011 56 1
    7 3 2012 25 0
    8 3 2013 30 0
    9 3 2014 30 1
    10 4 2009 40 0
    11 4 2010 41 0
    12 4 2013 35 1
    13 5
    14 ..

    By doing this I could create a sub- cross sectional database containing only the selected rows (in the example, the ones I marked with bold).

    I tried a couple of things with the "collapse" command, but I got stuck with it, and besides I am not quite sure whether this is the best alternative.

    I hope you can help me out and please let me know if you need more information.

    Thank you

    Cheers,
    Esteban

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str2 id int year byte(isei iv1)
    "1" 2008 35 0
    "1" 2009 40 1
    "1" 2011 55 1
    "1" 2012 60 1
    "2" 2010 55 0
    "2" 2011 56 1
    "3" 2012 25 0
    "3" 2013 30 0
    "3" 2014 30 1
    "4" 2009 40 0
    "4" 2010 41 0
    "4" 2013 35 1
    end
    bys id (year): egen max = max(isei)
    egen first = min(year / (isei == max)), by(id)
    drop if isei != max | year != first
    list, clean noobs
    
        id   year   isei   iv1   max   first  
         1   2012     60     1    60    2012  
         2   2011     56     1    56    2011  
         3   2013     30     0    30    2013  
         4   2010     41     0    41    2010
    More info on the first operation here: https://www.stata.com/statalist/arch.../msg00286.html
    Last edited by Ali Atia; 28 Nov 2020, 09:59.

    Comment


    • #3
      It worked !!

      Thank you very much, I really appreciate it.

      Best,
      Esteban

      Comment

      Working...
      X