Announcement

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

  • How to overcome these issues with dates variables?

    Hi,

    My questions are:

    1) how to convert birth date and admission date into usable format because when I try to generate new variable using this command gen dob2 = date(Birth_Date, "DMY") it does not work and give missing values for all observations which is not true. I am assuming because the year is not spelling out completely in the original variable as seen in the example?

    2) some observations under variable Surg_Date has date and time together, how to remove the time only and keep the date, also who to convert ##NULL into (0) or missing?

    Code:
    clear
    input str9(Birth_Date Admission_Date) str16 Surg_Date
    " 3-Jul-12" "31-Dec-20" "#NULL!"          
    "30-Aug-15" "29-Dec-20" "#NULL!"          
    "26-Nov-14" "29-Dec-20" "#NULL!"          
    "26-Mar-09" "28-Dec-20" "#NULL!"          
    "25-May-20" "31-Dec-20" "#NULL!"          
    "29-Jan-12" " 1-Jan-21" "#NULL!"          
    " 7-Dec-18" " 2-Jan-21" "#NULL!"          
    "29-Jul-72" "12-Nov-20" "#NULL!"          
    "29-Dec-20" "29-Dec-20" "#NULL!"          
    " 6-Sep-61" "30-Dec-20" "#NULL!"          
    "10-Aug-03" "15-Nov-20" "#NULL!"          
    "10-Jul-42" "22-Dec-20" "#NULL!"          
    "23-Apr-78" "30-Dec-20" "12/31/2020 12:00"
    "28-Dec-03" "31-Dec-20" "12/31/2020 12:00"
    "17-Sep-53" "30-Aug-20" "#NULL!"          
    "25-Aug-78" " 2-Jan-21" "#NULL!"          
    " 7-Mar-99" "30-Dec-20" "#NULL!"          
    "29-Nov-87" "30-Dec-20" "12/30/2020 12:00"
    " 9-Apr-13" "29-Dec-20" "#NULL!"          
    "28-Nov-20" " 4-Jan-21" "#NULL!"          
    end


    Thanks for helping

  • #2
    See the help for date() to find out how to specify a century, say by adding a third argument 2025.

    Comment


    • #3
      Code:
      gen dob2 = daily(Birth_Date, "DMY", 2022)
      gen adm_date = daily(Admission_Date, "DMY", 2022)
      gen surg_date = dofc(clock(Surg_Date,"MDYhm"))
      format %td dob2 adm_date surg_date
      The problem with your command was that you need to tell Stata how to resolve the two digit years. See
      Code:
      help date()

      Comment


      • #4
        Originally posted by Nick Cox View Post
        See the help for date() to find out how to specify a century, say by adding a third argument 2025.
        Thanks, that was useful

        Comment


        • #5
          Originally posted by Hemanshu Kumar View Post
          Code:
          gen dob2 = daily(Birth_Date, "DMY", 2022)
          gen adm_date = daily(Admission_Date, "DMY", 2022)
          gen surg_date = dofc(clock(Surg_Date,"MDYhm"))
          format %td dob2 adm_date surg_date
          The problem with your command was that you need to tell Stata how to resolve the two digit years. See
          Code:
          help date()

          Thank you man, you are a legend, problems solved with ease!

          Comment

          Working...
          X