Announcement

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

  • xtset - repeated time values within panel error

    Hi why does stata return the error when i run this code

    Code:
    sort ptid year2
    xtset ptid year2
    
    //ERROR: repeated time values within panel

    using the following dataset:


    Code:
    clear
    input float(ptid state year2)
    1 1 2003
    1 2 .
    1 3 .
    2 1 2003
    2 3 2018
    2 2 .
    3 1 2003
    end label values state q1
    label def q1 1 "primary", modify
    label def q1 2 "revised", modify
    label def q1 3 "dead", modify
    As you can see I have successfully run the code here (post 7)using fake data... and I do have repeated years in my variables found in this post, but I didn't obtain the error obtained above. May you please let me know what I'm doing wrong?

    https://www.statalist.org/forums/for...n-var-f-status

    Update:
    it turns out I have around 12 people who died and had the operation on the same day (using the full ddmmyy)

    I wouldn't like to lose this data by just dropping them....as this shows a procedure may be high risk

    How do I address the problem to allow me to use -xtset-
    Last edited by Rose Matthews; 22 Mar 2024, 12:00.

  • #2
    The issue here is that you have repeated years *within* your ID variable - 3 observations have state 1 and year 2003. ID-year pairs need to be unique, as was the case in your other example.

    Comment


    • #3
      Rose:
      as an aside to George's hepful reply, to avoid -repeated time values within panel- error, just -xtset- your data with -panelid- only, keeping in mind that, while this fix makes time-series operator unvailable, it still allows you to plug -i.year- as a predictor in the right-hand side of your regression equation.
      Kind regards,
      Carlo
      (StataNow 18.5)

      Comment


      • #4
        thanks for this, however,

        I can't just

        Code:
        xtset ptid 
        
        ///if I do not xtset the year that this means I can't use 
        
        tsfill 
        
        //error: time variable not set
        The aim to generate transition probabilities for treatment and control as you can see in the post here:
        https://www.statalist.org/forums/for...n-var-f-status

        Which I generated successfully using dummy data and with Clyde's insight.

        As seen in post 1 of this thread (update at 1100) I have 42 observations in the treatment that were operated on and died on precisely the same day using the format DD MM YY

        I can either drop these.... which I wouldn't like to as this may indicate that treatment is high risk...but I'm not sure what else to do....

        Comment


        • #5
          Rose:
          why not considering survival analysis, then to calulate transition probability (e.g., Weibull regression, if you have a set of other predictors), as reported in: Briggs A, Sculpher M, Claxton K. Decision modelling for health economic evaluation. Oxford: Oxford University Press; 2006:46-56?.
          Kind regards,
          Carlo
          (StataNow 18.5)

          Comment


          • #6

            I have done survival analysis several time before….
            but how would this be used to generate transition probabilities if I have 2 failures (death or revised) . And to be honest I haven’t seen this reported on statalist being used to create transition probabilities

            would you be able to give me an eg how you would do this?

            Comment

            Working...
            X