Time 如何选择事件的时间间隔?
我有一个包含以下变量的Stata数据集:Time 如何选择事件的时间间隔?,time,time-series,stata,Time,Time Series,Stata,我有一个包含以下变量的Stata数据集: clear input str11 datel str15 timel int a double b int c double time float(hours minutes event) "23-FEB-2006" "10:14:57.837759" . 45.04 2 36897837 10 14 . "23-FEB-2006" "10:14:57.990093" 100 . . 36897990 10 14 . "23-FEB
clear
input str11 datel str15 timel int a double b int c double time float(hours minutes event)
"23-FEB-2006" "10:14:57.837759" . 45.04 2 36897837 10 14 .
"23-FEB-2006" "10:14:57.990093" 100 . . 36897990 10 14 .
"23-FEB-2006" "10:14:57.993023" 100 . . 36897993 10 14 .
"23-FEB-2006" "10:14:57.993023" 1800 . . 36897993 10 14 .
"23-FEB-2006" "10:14:58.133639" . 45.04 1 36898133 10 14 .
"23-FEB-2006" "10:15:01.773054" . 45.04 1 36901773 10 15 .
"23-FEB-2006" "10:15:01.776960" . 45.04 1 36901776 10 15 .
"23-FEB-2006" "10:15:02.776896" . 45.04 3 36902776 10 15 .
"23-FEB-2006" "10:15:07.482650" . 45.04 5 36907482 10 15 .
"23-FEB-2006" "10:15:07.885944" . 45.04 3 36907885 10 15 .
"23-FEB-2006" "10:15:09.550877" . 45.04 7 36909550 10 15 .
"23-FEB-2006" "10:15:22.151906" 100 . . 36922151 10 15 1
"23-FEB-2006" "10:15:22.155812" 100 . . 36922155 10 15 1
"23-FEB-2006" "10:15:22.155812" 1200 . . 36922155 10 15 1
"23-FEB-2006" "10:15:22.155812" 300 . . 36922155 10 15 1
"23-FEB-2006" "10:15:22.155812" 100 . . 36922155 10 15 1
"23-FEB-2006" "10:15:22.642109" 200 . . 36922642 10 15 .
"23-FEB-2006" "10:15:22.832527" 100 . . 36922832 10 15 .
"23-FEB-2006" "10:15:22.990720" . 45.04 3 36922990 10 15 .
"23-FEB-2006" "10:15:23.311988" . 45.04 1 36923311 10 15 .
"23-FEB-2006" "10:15:23.319800" . 45.05 3 36923319 10 15 .
"23-FEB-2006" "10:15:23.331518" . 45.1 1 36923331 10 15 .
"23-FEB-2006" "10:15:23.335424" . 45.11 1 36923335 10 15 .
"23-FEB-2006" "10:15:23.335424" . 45.11 2 36923335 10 15 .
"23-FEB-2006" "10:15:23.336401" . 45.1 1 36923336 10 15 .
"23-FEB-2006" "10:15:23.336401" . 45.1 1 36923336 10 15 .
"23-FEB-2006" "10:15:23.336401" . 45.1 1 36923336 10 15 .
"23-FEB-2006" "10:15:23.336401" . 45.1 1 36923336 10 15 .
"23-FEB-2006" "10:15:23.336401" . 45.1 1 36923336 10 15 .
end
变量event在整个事件持续时间内假定值为1,或假定值为。否则
我想保持活动和活动前后10分钟的时间窗口
例如,在下面,您可以看到我希望保留事件,即当变量event=1时,在第17467行之前10分钟和第17471行之后10分钟,同时删除其他观察值:
数据集可以有多个事件 可以使用社区提供的命令rangestat执行此操作:
generate double datetime = clock(datel + substr(timel, 1, 12), "DMYhms")
rangestat (count) event, interval(datetime -1000 1000)
drop if event_count == 0
format datetime %tcDDmonCCYY_HH:MM:SS.sss
list datetime event event_count, sepby(event_count) abbreviate(15)
+----------------------------------------------+
| datetime event event_count |
|----------------------------------------------|
1. | 23feb2006 10:15:22.151 1 5 |
2. | 23feb2006 10:15:22.155 1 5 |
3. | 23feb2006 10:15:22.155 1 5 |
4. | 23feb2006 10:15:22.155 1 5 |
5. | 23feb2006 10:15:22.155 1 5 |
6. | 23feb2006 10:15:22.642 . 5 |
7. | 23feb2006 10:15:22.832 . 5 |
8. | 23feb2006 10:15:22.990 . 5 |
+----------------------------------------------+