Announcement

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

  • Converting Julian Calendar dates to Gregorian Calendar dates

    Dear All

    I have a dataset which, according to the variable labels, has had all dates recorded in the Julian calendar format (https://en.wikipedia.org/wiki/Julian_calendar) - however the actual variables seem to be in a stata format: e.g. datebth (date of birth) = 145941. I know that this date should be between the years 1982 and 1984 as this was when the study participants were born. However, if I format the date using %td I get 12 May 2367 - which doesn't make sense in either calendar.
    Here is what I think:
    • either the label is wrong and the dates are not saved in the Julian calendar - in this case I would be grateful if anyone knows which sort of format this is.
    • or I probably need to apply another formatting function (the datetime help file does not seem to contain such a function) - here I would be grateful if anyone knows which function I can use to convert the date into gregorian format.
    Many thanks for your thoughts on this,
    Max


  • #2
    It's best not to assume or speculate but to show us a data example. http://www.statalist.org/forums/help#stata explains
    how.

    Note that in Stata the term format has the strict meaning of setting a display format. It has nothing to do with setting or changing a storage type or any conversion calculations.

    Comment


    • #3
      Unfortunately the dataset I use is sensitive and stored in a data safe haven. Therefore I am not allowed to extract the data and nor am I allowed to apply any userwritten commands to it. I can only make my hypothetical example more concrete like this:

      use study.dta
      br datebth if studyid==XYZ > I see that the variable datebth is 145941
      format datebth %td
      br datebth if studyid==XYZ > I see that the variable datebth is now 12may2367

      Does this help?
      Last edited by Maximiliane Verfuerden; 03 Apr 2017, 05:34.

      Comment


      • #4
        The FAQ Advice I cited in #2 already gives you the answer to that: namely, you should invent a data example with the same structure if your data are confidential. But your extra details allow some progress.

        As already said, applying the format command will not carry out any calculations or conversions. That's a common misconception even among more experienced Stata users. More on that at http://www.stata-journal.com/sjpdf.h...iclenum=dm0067

        http://blog.stata.com/2011/01/05/usi...ther-software/ implies to me that you should do something like this


        Code:
        .    di %td 145941  + td(14oct1582)
        11may1982
        but variable-wide e.g.

        Code:
        gen long datebth2 = datebth + td(14oct1582) 
        format datebth2 %td 
        As off-by-one errors are all too easy in this territory, you should check a few dates back with your original datafile (SPSS???).

        Comment


        • #5
          Well, it is quite unlikely that the data is indeed in a Julian calendar format, as the Julian calendar was replaced with Gregorian quite a few years before any digital dataset was ever created.
          It also would have almost no impact on your dates, as the changes between the two were incredibly minimal. Your value of 145941 would give a strange result on both calendars.
          That value also does not make much sense in whatever format. Assuming it is a number of days, which would make most sense for a date of birth variable, the origin (the 0th day) would have to be somewhere in the middle ages. That makes it ever so slightly more likely that the calendar is indeed in Julian format, but I wouldn't guess it is.
          I dont think the limited amount of info you can provide will get you much useful answers here. You're going to have to ask the person that created the database, probably.

          edit: was typing this up whilst Nick had already posted his. His suggestion on the origin of dates in SPSS is probably your best guess
          Last edited by Jorrit Gosens; 03 Apr 2017, 06:00.

          Comment


          • #6
            Dear Both

            Thank you for your help Nick. Your code solved it - the dates correspond exactly to the dates we would expect based on a sample of manual records we had.

            RE Jorrit: Unfortunately, the people who created the original dataset (indeed in SPSS) are not around anymore, therefore nobody could ask them why they chose to enter the dates in Julian format. However, the variable label says "date of birth - Julian Calendar", as I have described in my first post above.

            And yes Nick you are right, I probably got confused using format to describe the 'conversion' between Julian and Gregorian calendar display; mainly because the datetime helpfile describes it as SRF to HRF conversion and I was expecting that a SRF to HRF is the type of conversion that needed to be applied.

            Many thanks,
            Max

            Comment


            • #7
              Good that you solved the problem.

              Gregorian dates are Stata readable in the broad sense that Stata can read integers! Otherwise as with dates based on any other origin than Stata's default, the origin needs translation (shifting) before display formats will do what you want.

              Comment

              Working...
              X