Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Help with data management


From   "Katia Bobulova" <[email protected]>
To   [email protected]
Subject   Re: st: RE: Help with data management
Date   Thu, 17 Jul 2008 17:55:13 +0200

Dear Nick,

thank you very much for your help with question 2.

Your suggestion:
bysort date time : egen min1 = min(price1)
by date time: egen max2 = max(price2)
gen diff = max2 - min1

now works very well. Thanks a lot!

For what concern question 1, i.e. hms command, I want to clarify that
I am using Stata9.2.
Is this the problem? Because I succeed to generate hours, minutes and
seconds but then I cannot transform my time in something like this:
6:30:00 because hms command does not work.

Is there any other command to achieve the same result in Stata 9.2?

Thank you very much for your time and your attention.

Best,
Katia
2008/7/17 [email protected] <[email protected]>:
> As a footnote to this:
>
> Katia's error message on trying to use a function -hms()- indicated to me that she was trying to use an -egen- function with -generate-.
>
> She could have been trying to use a Stata 10 function -hms()- within an earlier version of Stata. (Else why did she get an error message?)
>
> In Stata 10, users should note that the official function -hms()- differs from the user-written -egen- function -hms()-, and not just in so far as you can use the latter only with -egen-.
>
> In Stata 10 you can do this, if you have installed -egenmore- from SSC:
>
> . set obs 1
> obs was 0, now 1
>
> . gen seven = 7
>
> . gen thirty = 30
>
> . gen fifty = 50
>
> . egen hms_egen = hms(seven thirty fifty)
>
> . gen double hms_gen = hms(seven, thirty, fifty)
>
> . l
>
>     +----------------------------------------------+
>     | seven   thirty   fifty   hms_egen    hms_gen |
>     |----------------------------------------------|
>  1. |     7       30      50      27050   27050000 |
>     +----------------------------------------------+
>
> The result of -egen, hms()- is in seconds. The result of the function -hms()- is in milliseconds.
>
> From other details here I also surmise that Katia has access to documentation for Stata 10, but is trying to use the date-time stuff introduced in Stata 10 within an earlier version. That won't work.
>
> Nick
> [email protected]
>
> Nick Cox
>
> On 1)
>
> "didn't work" can mean about twenty different things. Always precisely say what you mean, e.g. error message, incorrect values, puzzling results, computer burst into flames.
>
> -egen, hms()- takes a varlist and varlists don't include commas. That is explicit in the help.
>
> -egen, hms()- works out the time as seconds after midnight, which is exactly what my -generate- statement also did.
>
> It thus beats me why you regard -egen, hms()- as what you want to do, but not my statement.
>
> You will clearly need to use the date (i.e. day) information as well. That step was not included in my advice.
>
> Nick
> [email protected]
>
> Katia Bobulova
>
> I tried to curry out your instructions, however I have still some
> problems with question 1 and 2:
>
> 1)I have the time in this format: 63000 and i want to construct a
> "timedate" variable, which contains both the data and the time.
>
> You told me that hms works only with egen, so I tired to do this:
>
> g hours=int(time/10000)
> g minutes=int((time-hours*10000)/100)
> g seconds=int(time-hours*10000-minutes*100)
> egen newtime=hms(hours, minutes, seconds)
> format newtime%tc
>
> But it doesn't work and the solution that you suggested me (i.e. gen
> long time_in_sec = 3600 * hours + 60 * minutes + seconds) is not
> appropriate because it changes time in seconds.
>
> 2008/7/14 [email protected] <[email protected]>:
>
>> Katia Bobulova asked three questions. My answers below.
>>
>> I have some problems in managing my dataset. I have a dataset with
>> high frequency data, with observations about time, date, price,
>> quantity and a code for the type of security.
>>
>> Question 1
>> ==========
>> I have the time in this format: 63000 and i want to construct a
>> "timedate" variable, which contains both the data and the time.
>>
>> First af all I tried to modify the format of the time typing:
>>
>> g hours=int(time/10000)
>> g minutes=int((time-hours*10000)/100)
>> g seconds=int(time-hours*10000-minutes*100)
>> g newtime=hms(hours, minutes, seconds)
>> format newtime%tc
>>
>> However, after typing hms() I receive this message:
>> Unknown function hms()
>> r(133);
>>
>> The next step would be typing something like:
>>
>> gen double timedate=date*24*60*60*1000+time
>> format timedate %tcNN/DD/CCYY_HH:MM:SS
>>
>> Answer 1
>> ========
>>
>> -hms()- is an -egen- function written by Kit Baum and is included in the
>> -egenmore- package from SSC. It will _only_ work with -egen-, not with
>> -generate-.
>>
>> But you don't need it. You did almost all the work yourself.
>>
>> Assuming that e.g. 63000 is 06:30:00 then given your variables -hours-,
>> -minutes-, -seconds-,
>>
>> gen long time_in_sec = 3600 * hours + 60 * minutes + seconds
>>
>
> *
> *   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/
>
> Privileged, confidential or patient identifiable information may be contained in this message. This information is meant only for the use of the intended recipients. If you are not the intended recipient, or if the message has been addressed to you in error, do not read, disclose, reproduce, distribute, disseminate or otherwise use this transmission. Instead, please notify the sender by reply e-mail, and then destroy all copies of the message and any attachments.
>
> *
> *   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/
>
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index