Announcement

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

  • how to categorise a variable for how long a woman has been part of a cohort until she gave birth.

    Hello
    Im trying to categorise a variable for the time for how long a woman has been part of a cohort until she gave birth.
    I calculated the difference between the date of registration and date of birth of the baby, and divided by 365,25.
    Then I would like to categorise the variable according to years of registration until she gave birth.
    Here there is the command:

    gen dnascregd_dif = (dnasccri-regdia)/365.25 if (dnasccri!=. | regdia!=.)

    replace dnascregd_dif = 1 if (dnasccri-regdia)/365.25 == 1 | (dnasccri-regdia)/365.25 == 2 | (dnasccri-regdia)/365.25 == 3
    replace dnascregd_dif = 2 if (dnasccri-regdia)/365.25 == 4 | (dnasccri-regdia)/365.25 == 5 | (dnasccri-regdia)/365.25 == 6
    replace dnascregd_dif = 3 if (dnasccri-regdia)/365.25 == 7 | (dnasccri-regdia)/365.25 == 8 | (dnasccri-regdia)/365.25 == 9
    replace dnascregd_dif = 4 if (dnasccri-regdia)/365.25 > 9

    label define dnascregd_lbl 1 "1-3 years" 2 "4-6 years" 3 "7-9 years" 4 "> 9 years"
    label values dnascregd_dif dnascregd_lbl

    tab dnascregd_dif, m

    When I try to tabulate the results, the STATA output says that there are too many values.

    Does someone knows how to correct this?
    Thank you

  • #2
    The difference in days divided by 365.25 is only very exceptionally going to evaluate as an integer. That is why your tabulation fails. In a really large dataset, many distinct values are likely for the result.

    Also, using 365.25 as the average number of days in a year is widely accepted in epidemiology as precise enough but in Stata there are now all kinds of age or date difference functions that don't involve approximations at all.

    By a convenient coincidence the most helpful-looking functions are at the beginning of

    Code:
    help datetime functions

    Comment


    • #3
      Originally posted by Nick Cox View Post
      The difference in days divided by 365.25 is only very exceptionally going to evaluate as an integer. That is why your tabulation fails. In a really large dataset, many distinct values are likely for the result.

      Also, using 365.25 as the average number of days in a year is widely accepted in epidemiology as precise enough but in Stata there are now all kinds of age or date difference functions that don't involve approximations at all.

      By a convenient coincidence the most helpful-looking functions are at the beginning of

      Code:
      help datetime functions
      Thank you!

      Comment

      Working...
      X