Announcement

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

  • How to mark weekday and weekend in time series plot?

    Hi everyone,

    I have a transaction dataset and I want to see if sales is different between weekday and weekend. My data looks as below:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(date sales)
    21833  626.5945
    21834  712.4763
    21835  721.8365
    21836  689.7701
    21837 557.52216
    21840  657.5135
    21841  682.9962
    21842  698.6862
    21843  648.1583
    21847  633.3751
    21848  619.1693
    21849  708.1619
    21853  805.4773
    21854   663.768
    21855  699.5377
    21856  677.3256
    21857  674.9991
    21858 586.50964
    21859  703.4135
    21860  814.9023
    21861 607.18097
    21862 588.91956
    21864  760.9409
    21865 565.75543
    21866  764.2806
    21867   811.433
    21868  694.6788
    21869   684.066
    21870  686.7653
    21871  625.9821
    end
    format %tdCCYY-NN-DD date
    I used the code:
    Code:
    graph twoway line sales date
    I want to add some marks to distinguish the days in weekday and weekend, but haven't figured out how. I wonder if anyone can help me with this.

    Thank you so much!

  • #2
    Thanks for the data example. One approach to get you started --

    Code:
    gen weekend  = (dow(date) == 0 | dow(date) == 6) 
    
    twoway connected sales date || ///
           scatter sales date if weekend, leg(order( 1 "Weekday" 2 "Weekend")) xtitle("") ylab(, angle(h))
    
    
    ttest sales, by(weekend)
    Hope this helps.

    Comment


    • #3
      Originally posted by Justin Niakamal View Post
      Thanks for the data example. One approach to get you started --

      Code:
      gen weekend = (dow(date) == 0 | dow(date) == 6)
      
      twoway connected sales date || ///
      scatter sales date if weekend, leg(order( 1 "Weekday" 2 "Weekend")) xtitle("") ylab(, angle(h))
      
      
      ttest sales, by(weekend)
      Hope this helps.
      Hi Justin,

      The code you wrote works perfectly well. That's exactly what I want. Thank you so much for your support and help!

      Comment

      Working...
      X