Announcement

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

  • Calculate number of days from selected date to the end of quarter

    Dear All,

    If I have a table as below:
    ClinicID Visited Date
    001 23Feb2021
    002 15Apr2021
    003 11Jun2021
    004 7Dec2021
    005 7Jul2021
    006 9Jan2021
    007 10Sep2021
    008 2Aug2021
    009 7Jan2021
    010 19Mar2021














    How can I calculate number of days from these dates to the end of its quarter?
    Outcome would be like a table as below:
    Clinic ID Visited Date N days
    004 7Dec2021 24
    Thank you in advance.
    Sophon
    Last edited by Sophon Yen; 04 Dec 2021, 00:53.

  • #2
    if date numeric,
    Code:
    gen want = dofq(1+qofd(date)) - date-1

    Comment


    • #3
      @Øyvind Snilsberg Thank you so much for this code, It worked like a charm.
      To be honest, I don't understand how this code work. Would you mind kindly share me any source codes to explain more details about those commands in stata.
      Warmly regards,
      Sophon

      Comment


      • #4
        the code in #2 in words is want is equal to first date of the next quarter minus visit date minus 1 (subtract 1 because you want days since end of quarter, not days since beginning of next quarter)
        https://www.stata.com/manuals13/u24.pdf

        Comment


        • #5
          Thank you so much.

          Comment

          Working...
          X