Announcement

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

  • Counting interrupted by end of week

    Dear all

    I have a panel data set. The data are daily and do not include weekends. In each day, a number of firms provide information x. This number of firms can change from one day to the other.

    My question is basic. I want to calculate the number of firms that have the variable x for a window of two days. I used the following code:

    Code:
    rangestat (count) number_of_providers=x, int(date 0 1)
    The day of the week variable in my dataset is "dayofweek" created by Stata, and as I have no weekends, it ranges from 1 to 5.

    My problem is that when using the code above, it calculates the number of firms that provide variable x for a two-day window as I wanted except for Fridays. On Fridays, it counts the number for this day only!

    How can I adjust the code so that it calculates the number for two days also for Fridays, i.e., Friday+Monday instead of only Friday?

  • #2
    rangestat is from SSC, as you are asked to explain (FAQ Advice #12).

    A data example would have helped (same place).

    This may help:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(date dayofweek x)
    23345 5  1
    23348 1  2
    23349 2  3
    23350 3  4
    23351 4  5
    23352 5  6
    23355 1  7
    23356 2  8
    23357 3  9
    23358 4 10
    23359 5 11
    23362 1 12
    end
    format %td date
    
    gen date2 = cond(dayofweek == 5, date + 3, date + 1)
    
    rangestat (count) wanted = x, int(date date date2)
    
    list, sep(0)
    
         +--------------------------------------------+
         |      date   dayofw~k    x   date2   wanted |
         |--------------------------------------------|
      1. | 01dec2023          5    1   23348        2 |
      2. | 04dec2023          1    2   23349        2 |
      3. | 05dec2023          2    3   23350        2 |
      4. | 06dec2023          3    4   23351        2 |
      5. | 07dec2023          4    5   23352        2 |
      6. | 08dec2023          5    6   23355        2 |
      7. | 11dec2023          1    7   23356        2 |
      8. | 12dec2023          2    8   23357        2 |
      9. | 13dec2023          3    9   23358        2 |
     10. | 14dec2023          4   10   23359        2 |
     11. | 15dec2023          5   11   23362        2 |
     12. | 18dec2023          1   12   23363        1 |
         +--------------------------------------------+

    Comment

    Working...
    X