Announcement

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

  • How to convert panel data into survival analysis data format and perform parameter regression

    Hello ,everyone!
    I'm doing research on the persistence of poverty recently . I want to use K-M survival analysis . I have a basic question, how to convert the panel data format into the survival analysis data format?I looked up some information, but still could not find the answer.
    This is part of my data. I hope someone can help me .I will appreciate it very much!
    Wave is the survey time, and poverty is the event variable.
    input wave poverty id
    1991 0 1
    1993 0 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 0 9
    1991 0 1
    1993 1 2
    1997 1 3
    2000 0 4
    2004 1 5
    2006 0 6
    2009 1 7
    2011 1 8
    2015 0 9
    1991 1 1
    1993 1 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 1 9
    1991 1 1
    1993 0 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 1 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 1 9
    1991 1 1
    1993 0 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 0 9
    1991 0 1
    1993 1 2
    1997 1 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 0 9
    1991 0 1
    1993 1 2
    1997 1 3
    2000 0 4
    2004 1 5
    2006 1 6
    2009 0 7
    2011 1 8
    2015 1 9
    1991 1 1
    1993 0 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 1 8
    2015 0 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 1 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 0 1
    1993 1 2
    1997 1 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 1 8
    2015 1 9
    1991 1 1
    1993 0 2
    1997 1 3
    2000 0 4
    2004 1 5
    2006 1 6
    2009 0 7
    2011 1 8
    2015 1 9
    1991 1 1
    1993 0 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 1 6
    2009 0 7
    2011 0 8
    2015 1 9
    1991 1 1
    1993 1 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 1 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 1 1
    1993 0 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 1 7
    2011 1 8
    2015 0 9
    1991 0 1
    1993 1 2
    1997 1 3
    2000 1 4
    2004 0 5
    2006 1 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 1 8
    2015 1 9
    1991 1 1
    1993 0 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 1 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 1 1
    1993 1 2
    1997 0 3
    2000 0 4
    2004 1 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 1 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 1 6
    2009 0 7
    2011 1 8
    2015 0 9
    1991 0 1
    1993 1 2
    1997 1 3
    2000 1 4
    2004 1 5
    2006 1 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 1 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 1 1
    1993 1 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 1 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 1 6
    2009 0 7
    2011 1 8
    2015 1 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 0 4
    2004 1 5
    2006 0 6
    2009 0 7
    2011 1 8
    2015 1 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 1 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 0 1
    1993 0 2
    1997 0 3
    2000 0 4
    2004 1 5
    2006 1 6
    2009 1 7
    2011 0 8
    2015 0 9
    1991 0 1
    1993 1 2
    1997 0 3
    2000 1 4
    2004 0 5
    2006 0 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 0 1
    1993 0 2
    1997 1 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 0 9
    1991 1 1
    1993 0 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 0 9
    1991 1 1
    1993 0 2
    1997 0 3
    2000 0 4
    2004 1 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 1 9
    1991 1 1
    1993 1 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 0 9
    1991 1 1
    1993 0 2
    1997 1 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 0 9
    1991 1 1
    1993 1 2
    1997 1 3
    2000 0 4
    2004 0 5
    2006 1 6
    2009 1 7
    2011 1 8
    2015 1 9
    1991 1 1
    1993 1 2
    1997 1 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 0 8
    2015 1 9
    1991 1 1
    1993 0 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 0 6
    2009 0 7
    2011 1 8
    2015 1 9
    1991 0 1
    1993 0 2
    1997 0 3
    2000 0 4
    2004 0 5
    2006 1 6
    2009 1 7
    2011 1 8
    2015 0 9
    end

  • #2
    I do not understand your data organization. Whatever it is, it clearly isn't panel data as every combination of id and wave appears 39 times! Moreover, every such combination is also associated with both poverty = 0 and poverty = 1 during at least one of its appearances.

    Ultimately in order to do a survival analysis on duration of poverty, we have to be able to figure out when poverty began and ended (if it ever ended) for each id. So please explain how one might do that with this unusual data set. I can't figure it out.

    Comment


    • #3
      Thank you, Clyde Schehter, for patiently reading my question. Sorry, when I asked questions, I got the wrong data and misled you . I have revised it, and now it is the panel data.
      input wave id poverty
      1991 1 0
      1993 1 0
      1997 1 0
      2000 1 0
      2004 1 0
      2006 1 0
      2009 1 0
      2011 1 0
      2015 1 0
      1991 2 0
      1993 2 1
      1997 2 1
      2000 2 0
      2004 2 1
      2006 2 0
      2009 2 1
      2011 2 1
      2015 2 0
      1991 3 1
      1993 3 1
      1997 3 0
      2000 3 1
      2004 3 0
      2006 3 0
      2009 3 0
      2011 3 0
      2015 3 1
      1991 4 1
      1993 4 0
      1997 4 0
      2000 4 1
      2004 4 0
      2006 4 0
      2009 4 0
      2011 4 0
      2015 4 1
      1991 5 0
      1993 5 1
      1997 5 0
      2000 5 0
      2004 5 0
      2006 5 0
      2009 5 0
      2011 5 0
      2015 5 1
      1991 6 1
      1993 6 0
      1997 6 0
      2000 6 0
      2004 6 0
      2006 6 0
      2009 6 1
      2011 6 1
      2015 6 1
      1991 7 0
      1993 7 1
      1997 7 0
      2000 7 0
      2004 7 0
      2006 7 0
      2009 7 0
      2011 7 0
      2015 7 0
      1991 8 0
      1993 8 1
      1997 8 1
      2000 8 0
      2004 8 0
      2006 8 0
      2009 8 0
      2011 8 0
      2015 8 0
      1991 9 0
      1993 9 1
      1997 9 1
      2000 9 0
      2004 9 1
      2006 9 1
      2009 9 0
      2011 9 1
      2015 9 1
      1991 10 1
      1993 10 0
      1997 10 0
      2000 10 1
      2004 10 0
      2006 10 0
      2009 10 0
      2011 10 1
      2015 10 0
      1991 11 0
      1993 11 1
      1997 11 0
      2000 11 1
      2004 11 0
      2006 11 1
      2009 11 1
      2011 11 1
      2015 11 1
      1991 12 0
      1993 12 1
      1997 12 1
      2000 12 0
      2004 12 0
      2006 12 0
      2009 12 0
      2011 12 1
      2015 12 1
      1991 13 1
      1993 13 0
      1997 13 1
      2000 13 0
      2004 13 1
      2006 13 1
      2009 13 0
      2011 13 1
      2015 13 1
      1991 14 1
      1993 14 0
      1997 14 0
      2000 14 1
      2004 14 0
      2006 14 1
      2009 14 0
      2011 14 0
      2015 14 1
      1991 15 1
      1993 15 1
      1997 15 0
      2000 15 0
      2004 15 0
      2006 15 1
      2009 15 1
      2011 15 1
      2015 15 1
      end

      Here are some of my ways. I don't know if I did it right.
      (1)
      sort id wave
      by id: gen wave1 = _n //Because there is a gap in the survey periods, I don't know if it is right to handle like this.
      tsset id wave1
      tsspell, cond(poverty == 1)
      egen longest = max(_seq),by(id) //The variable longest is the duration of poverty? How to calculate the duration of poverty in the case of multiple spells?
      (2)
      stset longest, failure(poverty) // I turned the above duration data into a section data.
      But how to do survival analysis with panel data ?

      Dear Clyde Schehter, my problem is a little long.But it has been bothering me for a long time. I am very grateful for your reply.

      Comment


      • #4
        Hi Xiaopei, here is the code I write based on my understanding of your issue.

        tsset id wave
        tsfill, full
        by id: replace poverty=poverty[_n-1] if poverty==.
        stset wave, id(id) failure(poverty)

        I fill in the missing value of poverty with the previous un-missing value. You may fill in with other values that are more appropriate.
        You may also define failure in other ways, e.g. when poverty is equal to 0 or 1.

        Comment


        • #5
          Dear Jin,thank you for your serious reply.
          The following is my reply, but I don't know if my understanding is correct.
          The command "stset wave, id(id) failure(poverty) "means wave is the duration of the poverty, time measured from 0. In my data ,wave is the survey year ,it is not the duration . So, In my aforesaid command ,I have to calculate the duration of poverty first.
          Or we can convert the panel data into two variables "The Year Poverty Began" and "The Year Poverty Ended". But I don't know how to do it yet.

          Comment


          • #6
            Code:
            clear*
            input wave id poverty
            1991 1 0
            1993 1 0
            1997 1 0
            2000 1 0
            2004 1 0
            2006 1 0
            2009 1 0
            2011 1 0
            2015 1 0
            1991 2 0
            1993 2 1
            1997 2 1
            2000 2 0
            2004 2 1
            2006 2 0
            2009 2 1
            2011 2 1
            2015 2 0
            1991 3 1
            1993 3 1
            1997 3 0
            2000 3 1
            2004 3 0
            2006 3 0
            2009 3 0
            2011 3 0
            2015 3 1
            1991 4 1
            1993 4 0
            1997 4 0
            2000 4 1
            2004 4 0
            2006 4 0
            2009 4 0
            2011 4 0
            2015 4 1
            1991 5 0
            1993 5 1
            1997 5 0
            2000 5 0
            2004 5 0
            2006 5 0
            2009 5 0
            2011 5 0
            2015 5 1
            1991 6 1
            1993 6 0
            1997 6 0
            2000 6 0
            2004 6 0
            2006 6 0
            2009 6 1
            2011 6 1
            2015 6 1
            1991 7 0
            1993 7 1
            1997 7 0
            2000 7 0
            2004 7 0
            2006 7 0
            2009 7 0
            2011 7 0
            2015 7 0
            1991 8 0
            1993 8 1
            1997 8 1
            2000 8 0
            2004 8 0
            2006 8 0
            2009 8 0
            2011 8 0
            2015 8 0
            1991 9 0
            1993 9 1
            1997 9 1
            2000 9 0
            2004 9 1
            2006 9 1
            2009 9 0
            2011 9 1
            2015 9 1
            1991 10 1
            1993 10 0
            1997 10 0
            2000 10 1
            2004 10 0
            2006 10 0
            2009 10 0
            2011 10 1
            2015 10 0
            1991 11 0
            1993 11 1
            1997 11 0
            2000 11 1
            2004 11 0
            2006 11 1
            2009 11 1
            2011 11 1
            2015 11 1
            1991 12 0
            1993 12 1
            1997 12 1
            2000 12 0
            2004 12 0
            2006 12 0
            2009 12 0
            2011 12 1
            2015 12 1
            1991 13 1
            1993 13 0
            1997 13 1
            2000 13 0
            2004 13 1
            2006 13 1
            2009 13 0
            2011 13 1
            2015 13 1
            1991 14 1
            1993 14 0
            1997 14 0
            2000 14 1
            2004 14 0
            2006 14 1
            2009 14 0
            2011 14 0
            2015 14 1
            1991 15 1
            1993 15 1
            1997 15 0
            2000 15 0
            2004 15 0
            2006 15 1
            2009 15 1
            2011 15 1
            2015 15 1
            end
            
            snapspan id wave poverty, replace gen(entry_year)
            
            stset wave, id(id) exit(time .) origin(entry_year) failure(poverty = 1)
            sts graph

            Comment


            • #7
              Thank you, professor Schechter.Thank you very much for taking the time to answer my questions.Your command helped me a lot.

              May I ask you another question?

              I just want to calculate the a single poverty spell and multiple poverty spells. What should be done with the aforementioned panel data in stata?







              Comment


              • #8
                I just want to calculate the a single poverty spell and multiple poverty spells.
                I'm sorry, but I don't understand what you mean. Can you illustrate what you want by showing a small example of your data and hand-worked results that you would like to get?

                Comment

                Working...
                X