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

RE: st: Hyphens in dates


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Hyphens in dates
Date   Fri, 16 Jul 2004 10:13:16 +0100

The first principles approach expounded here by 
Joseph Coveney (and by Kit Baum in a separate posting) 
is always good. 

An extra tip is to go straight to [R] split 
and look at the discussion there. If the manual 
is not to hand, the on-line help includes an 
example relevant to the problem here. 

Nick 
[email protected] 

Erica Seiguer

> >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).

Joseph Coveney 
 
> 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.

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