Announcement

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

  • Creating identifier variable equal to one for all the observations from the same person

    Dear all,

    I am working with panel data from a national survey. People interlude in the waves have a special ID number (pid). I am trying to create an identifier variable equal to one for all observation for the same person. How can this be done ?

    Kind regards,
    Gabriela

  • #2
    Gabriela:
    I find difficult to get how this variable can be useful in panel data analysis, as you wull end up with a variable composed entirely of 1.
    Anyway, you may want to try:
    Code:
    bysort pid: gen flag=1
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hi Carlo,

      that's true. 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. 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



      * 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
      [/CODE]

      Comment

      Working...
      X