A thread last week on handling data which contain both date and time led to
the creation of three new egen functions, which Nick Cox has kindly
included in his omnibus collection -egenmore-.
hms( hh mm ss ) generates an integer variable equal to the number of
seconds past midnight for a specific hour, minute, and second, recorded in
24-hour time.
dhms( date hh mm ss ) generates a double variable containing the "Stata
date" (days since 01Jan1960), with fractional part equal to the number of
seconds past midnight, from integer date variable 'date' (an ordinary %td
Stata date) and integer hh, mm, ss. The resulting variable can be used for
date/time arithmetic, such as the calculation of time intervals, with
resolution better than 1 second.
tod( time ) generates a string variable representing the time of day
associated with 'time' number of seconds past midnight; e.g. the variable
created by hms().
These functions join a number of time- and date-related functions in Nick's
egenmore collection. Additional functions to ease handling of elapsed time
intervals are under development.
The hms() and dhms() functions do not operate exactly like those in that
other statistical package mentioned by Liz Allred, but they provide
equivalent functionality and precision.