Announcement

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

  • Organizing data in a 4-week interval

    Hello Statalist:

    I have weekly data running from week 1 to week 104. I need to organize the data in a 4-week interval to do some statistical analyses. I can generate a new variable and replace the value of that variable, as shown below:

    gen myfourweek = .
    replace myfourweek == 1 if week >=1 & week <=4
    replace myfourweek == 2 if week >=5 & week <=8
    .
    .
    .
    However, this is very tedious as I have to run the codes many times. I am wondering if there are easy ways to do the same.


    Also, is there a way to summarize the variable, say sales, in a four-week interval, from a weekly sales data. I can summarize sales by week using the codes, below:

    table week, statistic (total sales) //week is a weekly time period variable

    Can I specify some option in this code to tell stata to summarize sales by a four-week interval ?

    Thanks in advance,

    Ramesh
    Last edited by ramesh ghimire; 03 May 2022, 12:45.

  • #2
    Code:
    . clear
    
    . set obs 104
    Number of observations (_N) was 0, now 104.
    
    . gen week = _n
    
    . gen wanted = ceil(week/4)
    
    . scatter wanted week

    Comment


    • #3
      Thanks Nick Cox

      Comment

      Working...
      X