Announcement

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

  • Cox with Triple Diff-in-Diff in Regression

    Hello,
    I have panel data of individuals who are born in a particular year and die in another year. Some individuals are of group A, and others are of group B. In addition, each individual lives in a specific location. In some of the locations, a reform was implemented. The introduction is staggered: in each location, the reform is introduced in a different year, and once it is introduced it is persistent.

    To be completely clear, this is my data structure:
    ID YEAR REFORM GROUP ALIVE
    1 1 0 A 1
    1 2 0 A 1
    1 3 0 A 1
    1 4 1 A 0
    1 5 1 A 0
    2 1 0 B 0
    2 2 0 B 1
    2 3 0 B 1
    2 4 0 B 0
    2 5 0 B 0
    3 1 0 A 0
    3 2 1 A 0
    3 3 1 A 1
    3 4 1 A 1
    3 5 1 A 1
    4 1 0 B 1
    4 2 0 B 1
    4 3 1 B 1
    4 4 1 B 1
    4 5 1 B 0


    I want to estimate the effect of the reform interacted with being in group A on the survival rate on the individuals. Hence I need to combine a Triple Diff-in-Diff with a Cox survival analysis.
    I am unsure how to do this in terms of structuring the data, setting it, and running the regression.
    Thank you very much.

  • #2
    I'm confused by your example data. How is it possible that ID2 and ID3 are dead in year1, and years 1 and 2, respectively, but then are resurrected in years 2 and 3, respectively?

    Comment


    • #3
      Thank you for your reply!
      They haven't been born yet in these years. Individuals are born and die in different years. So ID2 is born in year = 2 and dies in year = 4.

      Comment


      • #4
        So, I think you want this:
        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input byte(id year reform) str2 group byte alive
        1 1 0 "A " 1
        1 2 0 "A " 1
        1 3 0 "A " 1
        1 4 1 "A " 0
        1 5 1 "A " 0
        2 1 0 "B " 0
        2 2 0 "B " 1
        2 3 0 "B " 1
        2 4 0 "B " 0
        2 5 0 "B " 0
        3 1 0 "A " 0
        3 2 1 "A " 0
        3 3 1 "A " 1
        3 4 1 "A " 1
        3 5 1 "A " 1
        4 1 0 "B " 1
        4 2 0 "B " 1
        4 3 1 "B " 1
        4 4 1 "B " 1
        4 5 1 "B " 0
        end
        
        //    VERIFY THAT EACH ID IS IN THE SAME GROUP IN ALL YEARS
        by id (group), sort: assert group[1] == group[_N]
        
        //    ELIMINATE PRE-NATAL OBSERVATIONS
        by id (year reform), sort: egen entry = min(cond(alive, year, .))
        drop if year < entry
        drop entry
        
        //    CREATE SPAN DATA FOR -stset-
        snapspan id year reform alive, gen(time0) replace
        
        stset year, id(id) failure(alive = 0) time0(time0)
        encode group, gen(_group)
        
        stcox i.reform##i._group
        Note: The example data is not rich enough to represent the reform#group interaction, but presumably this will not be a problem in your real data.

        Comment


        • #5
          This is extremely helpful. Thank you very much!
          One more question, if I may. I have observations that are born before year=1. So I have a column "Birth_year" that sometimes gets the value 0 (or even below). How should I address that?
          Thank you again.

          Comment


          • #6
            You should eliminate from the data set any observations that precede the birth of the participant. It is clear from your explanation in #3 that you do not consider these people to be "Alive" pre-birth. Consequently, they are not at risk of death during that time period. So they are not informative about factors affecting the risk of death.

            Added: On reflection I may have misunderstood the question you are asking in #5. What role does this birth year variable play in your model and analysis? And why are you concerned about the possibility that it takes on zero or negative values?
            Last edited by Clyde Schechter; 05 Sep 2023, 09:21.

            Comment

            Working...
            X