Announcement

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

  • Tranforming DOB into age

    Hello guys,

    I am so glad I found this forum, as I am new to work with STATA and I am struggling a lot right now. If anyone could help I would very much appreciate it.

    QUESTION:

    I am trying to analyse cohort data where total of 875 subjects were enrolled between September 2000 and June 2002, and followed-up continued until June 2004.

    My aim is to investigate what is the effect of age on the outcome, however all I have is d.o.b variable. How do I transform it into age?
    I need to split the age into age groups of 0-1year, 1-2 years, 2-4 years.

    I tried to use ***stsplit ageband, at(1,2)*** however, when I checked it out after by using ***tab ageband*** it gave me the total of 1369 episodes (but I only have 875 subjects!!! )

    How is that possible? Am I missing something? Please help, I feel very helpless.

  • #2
    -stsplit- is not designed to do this task.

    If really all you have is date of birth, you are out of luck: you also need the date as of which age is to be computed. That might be date of study enrollment, or if this is an observational study it might be the date at which the the person achieved the condition under study. Anyway, I'm going to assume you really do have both a date of birth and a reference date, and that you want the age as of reference date. I'm going to assume these variables are called birth_date and reference_date, respectively.

    First, these need to be Stata internal numeric dates, not string variables that are read as dates by humans. If what you have are string variables (-des birth_date reference_date- will tell you), then you first need to convert them to Stata internal numeric dates using the -daily()- function. -help daily()-.

    After that it's simple:

    Code:
    gen age_in_years = (reference_date - birth_date)/365.25
    
    gen age_group = 0 if age_in_years < 1
    replace age_group = 1 if age_in_years >= 1 & age_in_years < 2
    replace age_group = 2 if age_in_years >= 2 & age_in_years <=4
    Notes:
    1. age_in_years will be fractional. That is somebody who is two and a half years old will have an age_in_years = 2.5. If you want to drop down to the next lowest integer (age at last birthday), then -replace age_in_years = floor(age_in_years). Similarly there is a -round()- function if you want to round to the nearest integer.
    2. You may want to put value labels on your age_group variable so your outputs are easier to read. See -help label define- and -help label values-.
    3. In your original question, people whoa re exactly 1 or 2 years old would belong to two age groups. I'm confident this is not what you want, and I have arbitrarily assumed that your intervals include the lower limit but not the upper. If you want to include the upper and not the lower, make the obvious replacements of inequality signs.

    Comment


    • #3
      Hello Janka,

      Welcome to the Stata Forum.

      You may transform date of birth in age just by dividing the difference of two dates by 365.25.

      For example, let's consider 2 variables: dateofbirth and datetoday:

      Code:
       . gen age = (datetoday - dateofbirth)/365.25
      If you don't have a variable with the date you wish to compare to (like "datetoday", that's no problem. You may specify the date to calculate the difference:

      Code:
      . gen age = (mdy(6,23,2012) - dateofbirth)/365.25
      You may wish to take a look at this text: http://www.ats.ucla.edu/stat/stata/modules/dates.htm

      Hopefully that helps.

      Please prefer to write "Stata" (not with all capital letters), as recommended in the FAQ.

      Best,

      Marcos
      Last edited by Marcos Almeida; 09 May 2016, 09:36.
      Best regards,

      Marcos

      Comment


      • #4
        It's an epidemiological tradition. seemingly, that the year being 365.25 days long is

        * a good enough approximation for all conceivable practical purposes

        * a easy rule for people to remember and follow so that consistent results are more likely

        But the exact calculation in principle is not difficult. There is a dedicated command on SSC:

        Code:
        ssc inst personage
        (that probably should be called person_age, but too late now). The help file bears witness to how tricky it can be to get all the details right, especially for leap years.

        Comment


        • #5
          Thank you very much guys for your help, it's much clearer now. I very much appreciate it.

          Comment

          Working...
          X