Announcement

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

  • convert buddhist year to christian year

    Hi, Stata users,

    My dataset have a lot of date variables, which is in Buddhist year (01jan2540).
    I want to convert to christian year for all variables that included date, which is like this (01jan2540 to 01jan1997).
    This two calendar has 543 years different.

    Could anyone tell me how can I write stata program code to change all in once?
    Sorry, I am weak at stata program.

    Thanks for my request.

  • #2
    Code:
    local difference = td(01jan2540) - td(01jan1997)
    gen christian_date = buddhist_date - `difference'
    format christian_date %td
    Note: This assumes that the two calendars are in all other respects identical, e.g. handling of leap years.

    Added: Actually, that doesn't work, because with a difference of 543 years, the leap years will be out of synch and we'll have some 01mar's turning into 29feb's, etc. So let's try a different approach:

    Code:
    gen christian_date = mdy(month(buddhist_date), day(buddhist_date), year(buddhist_date) - 543)
    Last edited by Clyde Schechter; 26 Apr 2017, 23:53.

    Comment


    • #3
      Thanks Clyde Schechter.

      Comment


      • #4
        Dear Clyde Schechter,
        I use this code.

        Code:
        foreach var of varlist datevisit12 datevisit13 datevisit14 datevisit15 {
        local difference = td(01jan2540) - td(31dec1996)
        gen `var'c = `var' - `difference'
        format `var'c %td
        }
        It seem work well,


        09jan2547 become 09jan2004
        13jan2547 become 13jan2004


        but it has problem in some date. Like ...

        07jul2547 become 06jul2004
        11jul2547 become 10jul2004
        03aug2547 become 02aug2004


        How can I handle only year without handling to day and month?

        Thanks for my question.

        Comment


        • #5
          See my "Added:" in #2. I realized this after I posted my response, and apparently your #3 crossed with it.

          Comment


          • #6
            Dear Clyde Schechter,

            You are genius. Now, perfect, well done!

            Thanks again.

            Comment

            Working...
            X