Announcement

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

  • Working with dates

    Hae, am planning to start a data collection on 29/03/2020 for my project. Being the data manager of this project I will be required to generate weekly progress reports. I need help in generating a code that start counting as from 29/03/2020 to 04/04/2020 as week 1 and so on.Instead of counting weeks from 1st Jan 2020.Kindly help.

  • #2
    Stata weeks are no use to you here. You have your own origin and each week is a block of 7 days starting then.


    Code:
    clear
    set obs 366
    gen day = mdy(3, 28, 2020) + _n 
    egen week = seq(), block(7)
    format day %td
    l in 1/49, sep(7)
    
        +------------------+
         |       day   week |
         |------------------|
      1. | 29mar2020      1 |
      2. | 30mar2020      1 |
      3. | 31mar2020      1 |
      4. | 01apr2020      1 |
      5. | 02apr2020      1 |
      6. | 03apr2020      1 |
      7. | 04apr2020      1 |
         |------------------|
      8. | 05apr2020      2 |
      9. | 06apr2020      2 |
     10. | 07apr2020      2 |
     11. | 08apr2020      2 |
     12. | 09apr2020      2 |
     13. | 10apr2020      2 |
     14. | 11apr2020      2 |
         |------------------|
     15. | 12apr2020      3 |
     16. | 13apr2020      3 |
     17. | 14apr2020      3 |
     18. | 15apr2020      3 |
     19. | 16apr2020      3 |
     20. | 17apr2020      3 |
     21. | 18apr2020      3 |
         |------------------|
     22. | 19apr2020      4 |
     23. | 20apr2020      4 |
     24. | 21apr2020      4 |
     25. | 22apr2020      4 |
     26. | 23apr2020      4 |
     27. | 24apr2020      4 |
     28. | 25apr2020      4 |
         |------------------|
     29. | 26apr2020      5 |
     30. | 27apr2020      5 |
     31. | 28apr2020      5 |
     32. | 29apr2020      5 |
     33. | 30apr2020      5 |
     34. | 01may2020      5 |
     35. | 02may2020      5 |
         |------------------|
     36. | 03may2020      6 |
     37. | 04may2020      6 |
     38. | 05may2020      6 |
     39. | 06may2020      6 |
     40. | 07may2020      6 |
     41. | 08may2020      6 |
     42. | 09may2020      6 |
         |------------------|
     43. | 10may2020      7 |
     44. | 11may2020      7 |
     45. | 12may2020      7 |
     46. | 13may2020      7 |
     47. | 14may2020      7 |
     48. | 15may2020      7 |
     49. | 16may2020      7 |
         +------------------+
    For an expansion of my first sentence, see


    Code:
    . search week, sj
    
    Search of official help files, FAQs, Examples, SJs, and STBs
    
    SJ-12-4 dm0065_1  . . . . . Stata tip 111: More on working with weeks, erratum
            . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
            Q4/12   SJ 12(4):765                                     (no commands)
            lists previously omitted key reference
    
    SJ-12-3 dm0065  . . . . . . . . . .  Stata tip 111: More on working with weeks
            . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
            Q3/12   SJ 12(3):565--569                                (no commands)
            discusses how to convert data presented in yearly and weekly
            form to daily dates and how to aggregate such data to months
            or longer intervals
    
    SJ-10-4 dm0052  . . . . . . . . . . . . . . . . Stata tip 68: Week assumptions
            . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
            Q4/10   SJ 10(4):682--685                                (no commands)
            tip on Stata's solution for weeks and on how to set up
            your own alternatives given different definitions of the
            week

    Comment


    • #3
      The date 29/03/2020 in SIF is a number

      Code:
      . di date("29/03/2020", "DMY")
      22003
      Because you count duration in days as End- Start+ 1, for any given day, after converting to SIF, you can determine the week number as the ceiling of (date-22003+1)/7. So for example

      Code:
      . di date("04/04/2020", "DMY")
      22009
      
      
      . di ceil((22009-22003+1)/7)
      1
      and the day after

      Code:
      . di date("05/04/2020", "DMY")
      22010
      
      . di ceil((22010-22003+1)/7)
      2

      Comment

      Working...
      X