Announcement

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

  • Paneldata - find next completed education

    Hi everybody

    I am using paneldata and need to find the next completed education following highschool. Note, it does not matter whether highschool was completed or not.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(id year highschool completed educational_type level)
    1 2009 1 1 1 1
    1 2010 1 1 1 2
    1 2010 0 0 5 1
    1 2011 0 0 0 .
    1 2012 0 1 2 1
    1 2013 0 1 2 2
    2 2011 0 0 0 .
    2 2012 0 0 0 .
    2 2013 1 1 1 1
    2 2014 1 1 1 2
    2 2015 0 0 0 .
    2 2016 0 1 4 1
    end
    Thank you!

    Best
    Gustav

  • #2
    Note that I cannot xtset my data, as I have two observations within the same year (2010 for id = 1). I need to somehow keep this information (as it is important) and still find the next completed education.

    Comment


    • #3
      I cannot figure out whether you want the educational_type or the level of the first completed education after high school. So, I give you both. Also, although you do not make it clear, I assume that by first completed after high school you mean the first completed after the last observation that has highschool == 1. I also assume that when you have two observations for the same id and the same year, the order in which they appear is to be preserved when identifying what precedes and what follows what.

      Code:
      //  MARK CURRENT SORT ORDER
      gen `c(obs_t)' obs_no = _n
      
      by id (obs_no), sort: egen final_obs_high_school = max(cond(highschool, obs_no, .))
      by id (obs_no): egen obs_next_completed_education ///
          = min(cond(obs_no > final_obs_high_school & completed), obs_no, .)
      gen next_completed_education_type = educational_type[obs_next_completed_education]
      gen next_completed_education_level = level[obs_next_completed_education]

      Comment


      • #4
        Thanks Clyde. Your code did exactly what I needed.

        Comment

        Working...
        X