Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Problem with datetime functions


From   George Vega Yon <[email protected]>
To   [email protected]
Subject   st: Problem with datetime functions
Date   Tue, 11 Jun 2013 10:18:31 -0400

Dear list members,

I'm facing a problem while generating an integer from day-time
variable. In short, what I (in stata %td format) have is

myday
01jan2002
02jan2002
03jan2002
04jan2002
...

What I want is

myday2
20020101
20020102
20020103
20020104
...

Which is I though I could generate by:

gen myday2 = year(myday)*10000 + month(myday)*100 + day(myday)

But acctually returns

myday2
20020100
20020102
20020104
20020104

So, it seems that stata is rounding my new variable. I don't want to
say that this is a bug, but what are the alternatives?.

I've solve this with:

format %tdCCYYNNDD myday
tostring myday, u gen(myday2) force
destring myday2, replace

myday2
20020101
20020102
20020103
20020104

But still, stata rounding my integers doesn't sound very good. Any ideas?

Thanks!

George Vega

PS: Running on windows 7
c(stata_version) = 12.1
c(version) = 12.1
c(born_date) = "18 Dec 2012"
c(flavor) = "IC"
c(os) = "Windows"
c(osdtl) = "64-bit"
c(machine_type) = "PC (64-bit x86-64)"
c(byteorder) = "lohi"



George Vega Yon
7 647 2552
http://cl.linkedin.com/in/georgevegayon
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index