Announcement

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

  • Calculating change in BMI, HBA1c...with longitudinal data

    I have panel data and want to calculate the change from one year to another, but I get the message "repeated time values within the panel." I have no duplicate observation. What should I do?

    Thanks

    Update: I found the solution!
    Last edited by Mamadou Sy; 18 Aug 2022, 11:58.

  • #2
    Mamadou:
    welcome to this forum.
    Please read the FAQ on how to post more effectively. Thanks.
    That said (and without other details from your side), the usual trick (which is valid provided that you do not plan to use time series-related operators, such as lags and leads) is to -xtset- your dataset with the -panelid- only.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      The message is telling you that you don't in fact have proper panel data. In your data somewhere there are observations having the same value of the panel identifier (presumably patient id or the like) and time variable (date). The first step is to find the offending surplus observations, and then figure out how they got there and how to deal with them.

      To find them, run:
      Code:
      duplicates tag panel_var time_var, gen(flag)
      browse if flag
      Replace the italicized parts with the actual names of your panel identifier variable and time variable.

      Study what you find in the browser. Something went wrong in the data management that created this data set, and you need to fix that. Seeing the observations may help you understand where things went wrong.

      Note: If you need additional, more concrete assistance, when posting back with additional questions, be sure to show example data that illustrates the problems you are having. Do that by using the -dataex- command. In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 17, 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-.

      Added: Crossed with #2. While the suggestion to -xtset- with just the panel identifier variable will make the error message go away, I recommend nevertheless exploring the offending observations first. O.P. mistakenly believes he has panel data. Presumably he has some reason for thinking that. If he is supposed to be working with panel data, then using the -xtset panel_var- approach will make the error message go away and will then allow him to proceed with analyzing the wrong data. If he is not supposed to be working with panel data and just misunderstood how -xtset- works, then the solution in #2 is fine. But he needs to be clear about what he is doing. At the moment, he is not.
      Last edited by Clyde Schechter; 18 Aug 2022, 12:02.

      Comment


      • #4
        I guess that

        either you forgot to specify a time variable to tsset or xtset

        or your data are more complicated than once per year.

        Or both. Please show the code you used to declare your data as longitudinal together with a data example.

        Sassy young people post things like this

        https://twitter.com/stelifanie/statu...83010817929221

        mocking the repeated request to show data examples. but there is all too much good reason for that. (Stephanie Sezen: feel free to come over and help out with answering questions!)

        EDIT:

        #2 #3

        What we tell you three times is true https://en.wikiquote.org/wiki/The_Hunting_of_the_Snark
        Last edited by Nick Cox; 18 Aug 2022, 12:05.

        Comment

        Working...
        X