Announcement

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

  • Missing marital status between years

    Hi all,

    What I am trying to do is identify all people who have reported being married but for two or more years they have reported no status. This is based on panel data 1984-2015. There is missing data in between status of being married. I tried using the below command (pid=perosnal ID, marstatus =1 if the person is married):

    by pid syear: gen cutoff=(marstatus!=marstatus[_n-1]) if marstatus ==1
    by pid: gen spell=sum(cutoff)
    by pid spell (syear), sort: gen spell_l = _N
    recode cutoff (.=0)

    However I still cannot manage. I wan to remove for example this person who has no reported status between 1987 and 1989. However for every person those years might be defferent


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte marstatus int syear long pid float(spell length cutoff)
    1 1984 3202 1  1 1
    1 1985 3202 2  1 1
    1 1986 3202 3  4 1
    . 1987 3202 3  4 0
    . 1988 3202 3  4 0
    . 1989 3202 3  4 0
    1 1990 3202 4 26 1
    . 1991 3202 4 26 0
    . 1992 3202 4 26 0
    . 1993 3202 4 26 0
    . 1994 3202 4 26 0
    . 1995 3202 4 26 0
    . 1996 3202 4 26 0
    . 1997 3202 4 26 0
    . 1998 3202 4 26 0
    . 1999 3202 4 26 0
    . 2000 3202 4 26 0
    . 2001 3202 4 26 0
    . 2002 3202 4 26 0
    . 2003 3202 4 26 0
    . 2004 3202 4 26 0
    . 2005 3202 4 26 0
    . 2006 3202 4 26 0
    . 2007 3202 4 26 0
    . 2008 3202 4 26 0
    . 2009 3202 4 26 0
    . 2010 3202 4 26 0
    . 2011 3202 4 26 0
    . 2012 3202 4 26 0
    . 2013 3202 4 26 0
    . 2014 3202 4 26 0
    . 2015 3202 4 26 0
    end
    label values marstatus d11104
    label def d11104 1 "[1] Married        1", modify

  • #2
    I think you want:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte marstatus int syear long pid
    1 1984 3202
    1 1985 3202
    1 1986 3202
    . 1987 3202
    . 1988 3202
    . 1989 3202
    1 1990 3202
    . 1991 3202
    . 1992 3202
    . 1993 3202
    . 1994 3202
    . 1995 3202
    . 1996 3202
    . 1997 3202
    . 1998 3202
    . 1999 3202
    . 2000 3202
    . 2001 3202
    . 2002 3202
    . 2003 3202
    . 2004 3202
    . 2005 3202
    . 2006 3202
    . 2007 3202
    . 2008 3202
    . 2009 3202
    . 2010 3202
    . 2011 3202
    . 2012 3202
    . 2013 3202
    . 2014 3202
    . 2015 3202
    end
    label values marstatus d11104
    label def d11104 1 "[1] Married        1", modify
    
    //    IDENTIFY SPELLS OF MISSINGNESS OF MARITALSTATUS
    by pid (syear), sort: gen spell_num = sum((missing(marstatus) != missing(marstatus[_n-1])) ///
        | _n == 1)
    by pid spell_num (syear), sort: gen spell_duration = _N
    by pid, sort: egen longest_missing_spell = max(cond(missing(marstatus), spell_duration, .))
    
    //    IDENTIFY PEOPLE WHO HAVE BEEN MARRIED
    by pid, sort: egen ever_married = max(marstatus == 1)
    
    //    DROP THOSE WHO HAVE BEEN MARRIED AND HAVE A MISSING SPELL TWO YEARS OR LONGER
    drop if ever_married & longest_missing_spell >= 2

    Comment


    • #3
      Hi Clyde,

      this actually works! So many thanks, highly appreciated !

      Best regards,
      Gabriela

      Comment

      Working...
      X