Announcement

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

  • Panel Data Help - "Repeated Time Values"

    Hi STATA Community!

    I have a question regarding panel data [this is my first time using the command]. I have a dataset which is all within one year. The date variable is properly formatted and I've grouped the individual ID #s to serve as the "panel variable."

    Where I'm running into a problem is defining the dataset as panel data. It returns the error: r(451): Repeated time values within panel

    I understand the nature of the error, as one 'person' (ID#s) could visit the same facility more than once in one day (time variable).

    Is there any way around this? There is a variable for visits, which would uniquely identify visits within a day per person, but this variable does not correspond to the date variable, making a time-series analysis unfruitful.

    I'd appreciate any thoughts the community might have, and thank you!

    PCF

  • #2
    There are at least two ways to deal with this.

    First it may be enough to just -xtset- the data with the panel variable and not mention any time variable there. It depends on what kind of analyses you want to do. If you will need to use time series operators such as leads and lags, or models with autoregressive structure, than this approach is not appropriate. But if you don't need those things, then you can simply omit any mention of a time variable in -xtset- and Stata will not complain.

    If, however, you do need those things, then you have a problem, because, for example, the "lag" of a variable cannot be defined if there is more than one possible observation that could be considered to be "the immediately preceding" one. Now, it I understand what you wrote in #1 correctly, you have, in addition to your date variable, a visit number variable which identifies the correct order of the visits within a given date. If that is the case, then you can create a new variable which orders the data by date and visit number, and then use that as the "time" variable in -xtset-. To wit:

    Code:
    by panel_id date (visit), sort: gen seq = _n
    xtset panel_id seq

    Comment


    • #3
      Clyde Schechter has a typo in the location of the left parenthesis on his first command: I believe what he intended was
      Code:
      by panel_id (date visit), sort: gen seq = _n
      xtset panel_id seq

      Comment


      • #4
        Thank you, William Lisowski, for correcting that error.

        Comment


        • #5
          Clyde and William -

          Thank you very much for your help, it worked perfectly without having to drop observations! I'll continue to plug forward with the other years of data! I'm new to the forum so I'm not sure how to approach follow-up questions (on another topic, same dataset). I assume it is best to help other users by creating a new, categorized thread. Perhaps I'll hear from you on that one. Much appreciated, again.

          Best,
          Peter

          Comment


          • #6
            Yes, when the topic changes, it is best to start a new thread. While it is tempting to think of these threads as dialogs between a questioner and a responder, they are read more widely than that. There are people who come here regularly and just read on topics, either generally or after specific search. To make the search engine useful, it is important that topics be informative and that threads stay on topic. So thanks for starting a new thread.

            Comment

            Working...
            X