Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Summarizing data by Timestamps


From   Eric Booth <ebooth@ppri.tamu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Summarizing data by Timestamps
Date   Mon, 7 Dec 2009 13:19:11 -0600

><
>

Diego:

I added some extra timestamps since you were interested in time periods of a couple of hours:


****
clear

input str20 timestamp          pressure 
"11/22/09 00:00"        120
"11/22/09 00:01"        123
"11/22/09 00:02"        119
"11/22/09 00:03"        115
"11/22/09 00:09"        123
"11/22/09 00:10"        122
"11/22/09 00:22"        112
"11/22/09 01:20"		2000
"11/22/09 01:27"		2100
"11/22/09 05:27" 		5000
"11/22/09 06:45"		10000
end

*format timestamp %tCNNDDYY_HH:MM
g double timestamp2 = clock(timestamp, "MD20Yhm")

**avg. by one hour interval**
g hour = hh(timestamp2)
egen one_hour_avg = mean(pressure), by(hour)

**take averages for different time periods from 1:00**
forv t = 2(1)6 {
egen hour_avg_`t' = mean(pressure)if hour<=(1+`t') & hour>=1
}

**or by collapse to get summary info by hour, etc**
preserve
collapse (mean) pressure , by(hour)
li
restore
*****


~Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754



On Dec 7, 2009, at 12:51 PM, Diego Bellavia wrote:

> Hello StataListers, 
> 
> I have such a dataset: 
> 
> Timestamp           Pressure 
> 11/22/09 00:00        120
> 11/22/09 00:01        123
> 11/22/09 00:02        119
> 11/22/09 00:03        115
> 11/22/09 00:09        123
> 11/22/09 00:10        122
> 11/22/09 00:22        112
> 
> etc...
> 
> As you see, Pressure values are reported by time (defined as a timestamp) every minute.
> Unfortunately, the system is not so precise to collect pressure every single minute so, 
> I do not necessarily have 60 measures in 1 hour. 
> Now I would like to compute averages for Pressure every pre-spcified time range, starting, as exmaple, 
> with ana average of all the values collected between 00:00 and 01:00 on 11/22/2009 but also being able to 
> change the time range from 1 hour, to 4 or 6 hours and so on. 
> 
> How can I do that in STATA, considering that I do not know how many measure are collected per hour ? 
> 
> Thank you in advance, 
> 
> Diego
> 
> 
> 
> 



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index