Announcement

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

  • How to find the day of the week

    Hi everyone,
    I have a clinical intervention data with adverse events. I want to see if adverse events are more likely to be reported during specific months (season), and/or days of the week. So, I need to create two categorical variables: one for the weekdays and the other for the month.
    Thank you.

    Here is the data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int ID str10 adverse_event_date
     1 "2019-01-30"
     2 "2018-03-24"
     3 "2018-03-22"
     4 "2018-10-25"
     5 "2018-07-19"
     6 "2018-04-03"
     7 "2018-12-12"
     8 "2018-09-04"
     9 "2019-01-30"
    10 "2019-01-30"
    11 "2018-12-10"
    12 "2018-08-15"
    13 "2018-07-20"
    14 "2018-11-05"
    15 "2018-12-12"
    16 "2018-07-03"
    17 "2018-12-11"
    end

  • #2
    Code:
    help datetime
    Then search in the pop-up window for "calendar month" and then "dow". It will show you the relevant functions to get this information. (Be sure to convert your string date into an "SIF" date first. The function for that's there, too.)

    Comment


    • #3
      Code:
      * Convert string date to Stata date
      gen daily_date = date(adverse_event_date , "YMD")
      format daily_date %td
      
      * Weeks of the year
      gen weekly_date = week(daily_date)
      
      *create monthly date
      gen monthly_date = month(daily_date)
      
      * Week days
      gen week_days = dow(daily_date )
      *Description: the numeric day of the week corresponding to date e d; 0 = Sunday, 1 = Monday,. . . , 6 = Saturday
      Regards
      --------------------------------------------------
      Attaullah Shah, PhD.
      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
      FinTechProfessor.com
      https://asdocx.com
      Check out my asdoc program, which sends outputs to MS Word.
      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

      Comment


      • #4
        Thank you for your help.

        Comment

        Working...
        X