Announcement

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

  • Longitudinal data with irregularly spaced waves

    Hi,

    I am using longitudinal data collected at unequal spaced intervals (1989, 1991, 1993, 1997, 2000....). I'm trying to figure out the individuals who participated in t0 survey but did not participate in t0+1 survey. I have a individual id for each person to check participation in each wave. The code below is giving me the number of people in each wave as opposed to those who dropped out. I;m not sure what I'm missing.

    xtset idind year
    gen leave=0 if idind==f.idind
    replace leave=1 if idind<. & f.idind==.
    replace leave=. if year==2015
    label var leave "=1 if R did not participate in survey in t+1"
    tab year leave
    tab year, sum(leave)
    tab year if esample==1, sum(leave)

  • #2
    When you use f.idind in the second command, you are going wrong, because your -xtset idind year- command tells Stata that, for example, f.year = 1990 when year = 1989, etc. And so you will never have leave == 0. Similarly your -replace leave = 1 if...- command does not do what you expect.

    I cannot give you corrected code because you did not show example data, so I cannot tell how your data are organized. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Thank you, Clyde. That certainly helped explain why the code didn't work. I apologize for not showing example data. This is a snapshot of the data.

      idind year
      111101002001 2011
      111101002001 2015
      111101004001 2011
      111101004002 2011
      111101005001 2011
      111101005001 2015
      111101005002 2011
      111101005002 2015
      111101010001 2011
      111101010001 2015
      111101010002 2011
      111101011001 2011

      Comment


      • #4
        OK, I get a sense of how your data looks now. But nowhere in this thread if you indicated whether going from 2011 to 2015 represents skipping or not, so this data does not help me write code.

        The general approach I would take is this. I would create a separate data set containing a list of all and only the years in which the survey was administered, and then create a successor variable that shows the next available year:

        Code:
        clear
        input int year
        1989
        1991
        1993
        1997
        2000
        end
        sort year
        gen successor = year[_n+1]
        tempfile successors
        save `successors'
        Then I would load in the survey data, and -merge- it with that file. Once merged, it is easy to identify who has skipped and who hasn't:

        Code:
        use my_survey_data, clear
        merge m:1 year using `successors', keep(match master)
        assert _merge == 3
        by idind (year), sort: gen byte skipped_next = year[_n+1] > successor if _n < _N
        Now, this won't work with your example data, because the successor file doesn't have an entry to match to 2011 or 2015, because you didn't give that information. But you can modify the code that creates the successor file so that you include all the actual years, and then it will work properly.

        Comment


        • #5
          Thank you, Clyde. This really helped.

          Comment

          Working...
          X