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]

st: RE: RE: Remove part of a string variable


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Remove part of a string variable
Date   Sat, 21 Aug 2010 19:44:57 +0200

<>

So if Beatrice only wants to display the time of day:


***********
clear*

//construct your variable
inp str18 mydate
"30dec1899 09:30:14"
end

gen double newdate=clock(mydate, "DM18Yhms")
format newdate %tc 

//only want time of day...
format newdate %tcHH:MM:SS

l, noo
***********

As she can see here, this is just -format-ting, not changing the values. If
Beatrice wanted to hold the time permanently, she can -tostring- the thing
via 

-tostring newdate, generate(mynewdate) force format(%tcHH:MM:SS)-


HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss
Sent: Samstag, 21. August 2010 18:51
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: Remove part of a string variable


<>

You say your variable is a "double" data type? If so, it is numeric, and
-split- only works for strings. 


What you showed in your post as 

30dec1899 09:30:14

is really 

di %20.0fc clock("30dec1899 09:30:14", "DM18Yhms")
=
-1,893,508,186,000


So what you really want is to extract a component, not split a string, as in


-help dates_and_times, mark(extracting)-.


HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Beatrice Crozza
Sent: Samstag, 21. August 2010 17:57
To: statalist
Subject: st: Remove part of a string variable

Dear All,

when I upload my data into Stata from my Access file (using the odbc
function) the time variable that I have becomes:

30dec1899 09:30:14

And it is in a double format.

I want to remove from my variable time the part 30dec1899.

I tried with generate splitat and with split time, p("30dec1899") but
they don't work.

Could you please help me?

Thank you very much.
Bea

*
*   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/

*
*   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