Announcement

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

  • Stata Date Format from a Fraction Year

    After extinguishing all efforts, I am reaching out to you to perhaps have a bit of Stata help regarding the dates.

    I have a DOB variable with data as:

    84.57
    85.68
    89.53
    87.46

    The first two numbers are 2 number years, the prefix being 19 (i.e., 1984, 1985, 1989, 1987) and the two numbers after the decimal are the fraction years; for example 1984 + 0.57 years. How can we convert the given numbers to Stata dates? I am assuming we are changing 0.57 to DOY first (no need for leap year adjustment, assuming 365.25 days in a year will do), but I didn't have any success getting the required output for this. Any help will be hugely appreciated.

    Thanks much.

  • #2
    Oddly enough, the following post from six hours before your post asks a very similar question, to which an answer has been supplied.

    https://www.statalist.org/forums/for...-fraction-year

    Comment


    • #3
      Hi William, thanks for your reply. That could be me as well as I posted this in 2 different forums but I was not able to find the response to my post though. I am not sure which post you were referring to and would love to know. Thanks.

      Comment


      • #4
        William gave a link in #2.

        Comment


        • #5
          Hi Nick, the link by William directs me to a post originally created by me; but no response to the post.

          Thanks

          Comment


          • #6
            My mistake, the link in #2 should have been

            https://www.statalist.org/forums/for...-form-in-stata

            Comment


            • #7
              Thanks much, William and Nick in engaging in trying to tackle this problem. I was also able to solve this problem by adopting the Stata elapsed date technique:

              If the variable is DOB,

              gen DOB1 = real(DOB)
              gen NEWDOB = ((DOB1+1900) - 1960)*365.25
              format NEWDOB %td

              Comment


              • #8
                Some further thoughts on this problem.

                In the code in post #7 my inclination would be to use floor() when generating NEWDOB as the code in the topic I linked to did, to ensure that the result will be a whole number. Since SIF daily dates are meant to represent a whole number of days, it is not clear how code will react to a fractional portion. I know that in my programming I've never done anything to confirm that dates I'm doing arithmetic on are indeed whole numbers - it never occurred to me that they might not be so . It appears that Stata formats like %td and %tm and %ty treats fractional parts that way.

                You show 2 digits of precision in your data; a single day is .00273973 of a 365-day year. If your actual data does not have greater precision, your birth dates will be lumped into 100 distinct days.
                Code:
                . display %td 365.25*round(1/365,.01) " " %td 365.25*round(2/365,.01)
                01jan1960 04jan1960
                Finally, the code in post #7 assumes that 85.00000 would represent January 1 1985 in the data.

                Comment

                Working...
                X