Announcement

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

  • Break in consecutive values to identify groups

    Suppose I have a dataset like this:

    clear
    set obs 20
    gen x = 1
    gen id = 1 in 1/10
    replace id = 2 in 11/20
    replace x = x + 5 in 6/10
    replace x = x + 5 in 16/20
    As you can see, there is a break in the x variable. I would like to group observations based on a break, i.e., have groups id11 and id12 for id = 1 with the break of the value as the delimiter of the variable.

    This is just an example; more generally, I have a dataset with minute-level data that crosses the day delimiter, and I would like to identify a night (e.g. starting at 10 PM and ending at 6 AM). Since I have minute-level data, there are breaks where on the same date the difference between times is higher than 1 minute (e.g. jumping from 6AM to 11PM - the start of a new night). I thought of using these jumps to identify the nights since dates as groups, in this case, are useless (because they encompass both the beginning of the next night and the end of the previous one).

    Any ideas are appreciated.

  • #2
    Code:
    ssc desc group1d
    will find a command that may help. The command name is sufficiently unusual that a Google will find other discussions, of which be sure to find a 2013 thread on stats.stackexchange.com

    Comment

    Working...
    X