Announcement

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

  • Calculating duration of follow-up time

    Hi everyone,

    I am analyzing mortality data from the National Health Interview Survey. The public use data file includes year of interview and year of death. I want to use these two variables to calculate duration of follow-up using these criteria:

    a) if the respondent died in the same year when they were interviewed, assign 0.5 years of follow-up time.
    b) assign all others, 0.5 years of follow-up time during the year of their interview, full year of follow-up for each year after their year of interview, until the year prior to their death, and then another 0.5 year of follow-up during the year of their death.

    As you can see in the screenshot below among those who were interviewed in 1986, 168 died the same year. Of the remaining, 385 died the next year; 481 the following year and so on.

    Click image for larger version

Name:	year.png
Views:	1
Size:	22.9 KB
ID:	1476237


    Both year variables (year of interview and year of death) are numeric. I generated a new variable by taking the difference between the two year variables and assigned a value 0.5 if the difference was 0. But am having a hard time creating a loop to automate the process to complete (b). Any help is greatly appreciated. I'm using Stata 14 on Windows 10.

    Thanks,

    Ahmed
    Last edited by Ahmed A Arif; 25 Dec 2018, 19:13.

  • #2
    Welcome to Statalist, Ahmed.

    As you can tell, your screenshot was not posted correctly. That happens to me often when I try to post pictures of data. But the real problem is, screenshots are not the appropriate way to post samples of data on Statalist.

    Please take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

    Please be sure to use the dataex command to show example data. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run ssc install dataex to get it. Either way, run help dataex and 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.

    But with that said, I'll take a try at guessing what your data is like. It seems to me iif you know the interview year and the year of death - lets call them I and D - then the number you seek is D-I, except that if D=I you want the value to be 0.5. No loop needed, unless the data I can't see doesn't look as I imagine it looks from your description. So Stata can do that in a single expression:
    Code:
    generate futime = cond(D>I,D-I,0.5)
    or equivalently
    Code:
    generate futime = max(D-I,0.5)

    Comment


    • #3
      Thanks, William. Rookie mistake. Here is the table using dataex. I am trying to create a loop to automate the process.

      Code:
      . tab year mortdody
      
          Survey |                           Year of death
            year |      1986       1987       1988       1989       1990       1991 |     Total
      -----------+------------------------------------------------------------------+----------
            1986 |       168        385        481        476        485        452 |    35,654
            1987 |         0        370        817        893        875        932 |    71,451
            1988 |         0          0        351        832        874        870 |    71,961
            1989 |         0          0          0        355        752        809 |    68,592
            1990 |         0          0          0          0        316        780 |    70,579
            1991 |         0          0          0          0          0        316 |    70,127
            1992 |         0          0          0          0          0          0 |    70,117
            1993 |         0          0          0          0          0          0 |    63,886
            1994 |         0          0          0          0          0          0 |    66,636
            1995 |         0          0          0          0          0          0 |    56,371
            1996 |         0          0          0          0          0          0 |    34,863
            1997 |         0          0          0          0          0          0 |    55,243
            1998 |         0          0          0          0          0          0 |    51,046
            1999 |         0          0          0          0          0          0 |    49,539
            2000 |         0          0          0          0          0          0 |    50,611
            2001 |         0          0          0          0          0          0 |    50,459
            2002 |         0          0          0          0          0          0 |    46,758
            2003 |         0          0          0          0          0          0 |    47,102
            2004 |         0          0          0          0          0          0 |    49,483
      -----------+------------------------------------------------------------------+----------
           Total |       168        755      1,649      2,556      3,302      4,159 | 1,080,478
      I calculated the duration as:
      Code:
      gen duration= (mortdody- year) if mortstat==1  *mortstat=1 if deceased, 0 presumed alive.
      I am having difficulty with (b) assign all others, 0.5 years of follow-up time during the year of their interview, full year of follow-up for each year after their year of interview, until the year prior to their death, and then another 0.5 year of follow-up during the year of their death.
      Last edited by Ahmed A Arif; 25 Dec 2018, 19:39.

      Comment


      • #4
        I am having difficulty with (b) assign all others, 0.5 years of follow-up time during the year of their interview, full year of follow-up for each year after their year of interview, until the year prior to their death, and then another 0.5 year of follow-up during the year of their death.
        I am having difficulty understanding how this would produce different results than the duration you have already calculated with the generate command shown in post #3. Suppose year = 1986 and mortdody=1990. Then you will assign that observation 0.5 (for 1986) +1+1+1 (for 1987-1989) +0.5 (for 1990) which totals to 4 which is exactly 1990-1986.

        Comment


        • #5
          I neglected to replace the value of duration with 0.5 if the difference was 0. It works now. Thanks

          Comment

          Working...
          X