Announcement

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

  • Missing values for Sunday dummy

    Hi,

    I am attempting to create dummy variables for each day of the week. I am using the following code:
    gen day = 1 if (dow(A) == 1)

    replace day = 2 if (dow(A) ==2)

    replace day = 3 if (dow(A) ==3)

    replace day = 4 if (dow(A) ==4)

    replace day = 5 if (dow(A) ==5)

    replace day = 6 if (dow(A) ==6)

    replace day = 7 if (dow(A) ==7)

    label define day 1 “Monday” 2 “Tuesday” 3 “Wednesday” 4 “Thursday” 5 “Friday” 6 “Saturday” 7 “Sunday”

    label value day day

    I am using this as my time series data gives numerical dates e.g. 1/01/2004 instead of the day and month written out. I want to account for the seasonality of my data but when I use this code it gives me missing values (a dash) for all days that are sunday. Is there something wrong with the code?

  • #2
    Probably you do not have any data for Sundays. This may make sense if your data concerns some activity which does not take place on this day, e.g., stock market trading in many countries.

    Comment


    • #3
      I don't see anything wrong with your code, except that it could be considerably simplified by just doing
      Code:
      gen byte day = dow(A)
      and then labeling it as before.

      Comment


      • #4
        Actually, on #1, Sunday is coded 0. So that is your issue.

        dow(e_d)
        Description: the numeric day of the week corresponding to date e_d; 0 = Sunday, 1 = Monday, ..., 6 = Saturday
        Domain e_d: %td dates 01jan0100 to 31dec9999 (integers -679,350 to 2,936,549)
        Range: integers 0 to 6 or missing

        Comment


        • #5
          There is a simpler explanation.

          The results of dow() run from 0 for Sundays through to 6 for Saturdays, so a result of 7 is impossible as well as not found in your data. One strategy here is to check the help:

          Code:
          help dow()
          In any case, the problem is not one of missing values, but of absent values... Missing value has a clear Stata meaning of a value present in your data but missing in a specific sense.

          EDIT == #4
          Last edited by Nick Cox; 13 Dec 2022, 10:07.

          Comment

          Working...
          X