Announcement

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

  • Dropping respondents with non-consequitive observations in a panel

    I have a panel data-set (unbalanced) in which individuals are observed for up to 4 years. For my analysis, I only want to keep those observations when the respondents were working. For this reason I want to drop those respondents who have non-consecutive appearances in the data.
    For example, if respondent x was working in period 1 and 3 but was unemployed in periods 2 and 4 I want a code that will drop all observations from this respondent altogether. On the other hand, I want to keep any respondent who has at least 2 consecutive observations when he/she was working. For example, if a respondent y was working in periods 1 and 2 but then he/she was unemployed in period 3 and 4 I want to keep him/her in the data.

    Thanks in advance
    Last edited by Christina Chara; 19 Feb 2015, 14:34.

  • #2
    Several threads on this site raise the same question: search for "consecutive".

    For example, see a very recent thread
    http://www.statalist.org/forums/foru...e-observations with pointers to tsspell (SSC).


    Comment


    • #3
      So you need to first create variables marking spells of employment and their duration. I'll assume each respondent is identified by a variable id, and that the time periods are identified by a variable called period, and that there is a dichotomous variable called employed ( 1 = employed, 0 = unemployed)

      Code:
      xtset id period
      by id period, sort: gen spell = 1 if employed == 1 & L1.employed != 1
      by id (period): replace spell = sum(spell) if employed == 1
      by id spell, sort: gen spell_length = _N
      replace spell_length = 0 if employed == 0
      by id (spell_length), sort: keep if spell_length[_N] >= 2
      Note: This retains all respondents who have at least one two-period run of employment, and it retains all of their data, including the periods where they were unemployed and any other spells that were shorter. That is my understanding of what you want.

      Comment


      • #4
        With Clyde's set-up, this would be a tsspell approach.

        Code:
        ssc inst tsspell
        xtset id period
        tsspell, cond(employed)
        bysort id (_seq) : keep if _seq[_N] > 1
        Last edited by Nick Cox; 19 Feb 2015, 15:12.

        Comment


        • #5
          Assuming that employment is coded 1/0, this should also work:

          Code:
          bysort id (period): gen diff = employed[_n+1] * employed[_n]
          bysort id (period): egen maxdiff = max(diff)
          keep if maxdiff==1
          Last edited by Alex Gamma; 19 Feb 2015, 16:32.

          Comment

          Working...
          X