Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Hyphens in dates


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: Hyphens in dates
Date   Fri, 16 Jul 2004 09:52:49 +0900

Erica Seiguer wrote:

>I have a date variable which lists dates as
>
>MM-DD-YR
>
>I want to remove the hyphens/dashes, but can't find anything in any
>manual about this.
>
>Also, sometimes the actual time is also included like:
>
>MM-DD-YR HH:MM.
>
>In this case, I want to dump the time stamp, and keep the date (without
>the hyphens).

----------------------------------------------------------------------------

As you describe the examples, the date variable and date-time variable would
be strings, so you can use Stata's string functions (-help functions-
or -help strfun-) to remove unwanted characters and to keep a specified
number of characters within the string.

Assuming that there aren't any typographical errors in the following, for
the first case (MM-DD-YR), for a date variable named dashed_date, the
command would be -generate str6 dedashed_date = subinstr(dashed_date,
"-","", .)-,  and for the second case (MM-DD-YR HH:MM), either  -generate
str6 dedashed_detimed_datetime = substr(subinstr(dashed_datetime, "-", "",
.), 1, 6)- or -generate str6 dedashed_detimed_datetime =
subinstr(substr(dashed_datetime, 1, 8), "-", "", .)-.

You might also be interested in -help dates- and what is referenced there.

Joseph Coveney





*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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