Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: clock function accuracy


From   Phil Clayton <philclayton@internode.on.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: clock function accuracy
Date   Wed, 22 Feb 2012 23:45:35 +1100

> gen date2 double = clock(date, "YMDhm")
should be
gen double date2 

The syntax is outlined in -help generate-:

	generate [type] newvar[:lblname] =exp [if] [in]

If you -describe- your dataset you'll see that your date variables are being created as float rather than double precision.

What I don't understand is why Stata even allows your -gen- command - this shouldn't be valid according to the above syntax. On my version (12.1) it seems to allow you to specify a variable type after the new variable's name, but it proceeds to ignore that type.

Example:
. clear

. gen a double=1

. gen b str9=1

. gen c float="string variable"

. gen d not_a_vartype=0
too many variables specified
r(103);

. describe

Contains data
  obs:             0                          
 vars:             3                          
 size:             0                          
-----------------------------------------------------------------------------------------------------------------------------------
              storage  display     value
variable name   type   format      label      variable label
-----------------------------------------------------------------------------------------------------------------------------------
a               float  %9.0g                  
b               float  %9.0g                  
c               str1   %9s                    
-----------------------------------------------------------------------------------------------------------------------------------
Sorted by:  
     Note:  dataset has changed since last saved

This is rather confusing!

Phil

On 22/02/2012, at 11:33 PM, Emmanouil Mentzakis wrote:

> Hello,
> 
> I am trying to convert some string dates to dates in Stata format but
> I am having some difficulty with accuracy (probably is a problem of me
> not understanding some details). When I convert and format, some dates
> appear as expected but other don't. When observing the entries in the
> editor all new dates have extra second added to them. Below is an
> example. I would be grateful if anyone could help.
> 
> If I am trying to match datasets based on date/time do these extra
> second matter?
> 
> Thanks
> Manos
> 
> 
> ***Example
> 
> clear*
> 
> input str16 date
> "2002-01-01 02:00"
> "2002-01-01 03:00"
> "2002-01-01 06:00"
> "2002-01-01 07:00"
> "2002-01-01 08:00"
> end
> 
> gen date2 double = clock(date, "YMDhm")
> format date2 %tcDD-Mon-CCYY_HH:MM
> list
> 
> gen newdate = date+":00.000"
> gen date3 double = clock(newdate, "YMDhms")
> format date3 %tcDD-Mon-CCYY_HH:MM
> list
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index