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: AW: AW: converting varying formats of string dates into Stata dates


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: AW: converting varying formats of string dates into Stata dates
Date   Thu, 29 Jul 2010 16:58:52 +0200

<> 

Upon further consideration: Need to be more careful. BTW, any other date
-format-s can pose new and unexpected problems, so check after each change
whether what is happening to the data is in your best interest:

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

inp str9 todate1 
 "30-Jun-99"
 "10/15/99"
 "4/15/1998"
 "4/15/1998"
 "8/15/1998"
 "3/15/00"
 "6/1/1998"
 "6/1/1998"
 "1-MAR-00"
 "1-MAR-00"
 "1-MAR-00"
 "1-MAR-00"
 "02/15/98"
 "12/01/98"
 "1-AUG-00"
 "8/15/1998"
 "8/15/1998"
 "6/30/1998"
 "6/30/1998"
 "7/1/1999"
end

//clean dates
split todate1, parse(- /)
destring todate13, replace
replace todate13=2000+todate13 if inrange(todate13, 0, 10)
replace todate13=1900+todate13 if inrange(todate13, 90, 99)

//get newdate and turn into Stata date
replace todate1=todate11+"/"+todate12+"/"+string(todate13)
drop todate1?
gen mydate=date(todate1, "DMY", 1990)

//separate into good and bad dates
separate todate1, by(mi(mydate))

//replace with new strategy the missing ones
replace mydate=date(todate11, "MDY", 1990) if mi(mydate)

drop todate??
form mydate %tdMon_DD,_CCYY

list, noo
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Martin Weiss
Gesendet: Donnerstag, 29. Juli 2010 16:39
An: [email protected]
Betreff: st: AW: converting varying formats of string dates into Stata dates


<> 

You can peel this off one by one using -separate- with an expression:


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

inp str9 todate1 
 "30-Jun-99"
 "10/15/99"
 "4/15/1998"
 "4/15/1998"
 "8/15/1998"
 "3/15/00"
 "6/1/1998"
 "6/1/1998"
 "1-MAR-00"
 "1-MAR-00"
 "1-MAR-00"
 "1-MAR-00"
 "02/15/98"
 "12/01/98"
 "1-AUG-00"
 "8/15/1998"
 "8/15/1998"
 "6/30/1998"
 "6/30/1998"
 "7/1/1999"
end

gen mydate=date(todate1, "MD20Y")
//weed out the ones still missing
separate todate1, by(mi(mydate))

list, noo
*************

Then it is on to the next set of problematic dates...


HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Kate Rohrbaugh
Gesendet: Donnerstag, 29. Juli 2010 16:22
An: [email protected]
Betreff: st: converting varying formats of string dates into Stata dates

Greetings Statalist:
 
First, I hope my attempts at removing the HTML text were successful.  If
not, apologies in advance.

Second I have several fields that have dates in all sorts of manner, for
example (and there are more types, like mar-01-2000, this is just a
smattering):

. l2 todate1 in 1/20

  +-----------+
  |   todate1 |
  |-----------|
  | 30-Jun-99 |
  |  10/15/99 |
  | 4/15/1998 |
  | 4/15/1998 |
  | 8/15/1998 |
  |-----------|
  |   3/15/00 |
  |  6/1/1998 |
  |  6/1/1998 |
  |  1-MAR-00 |
  |  1-MAR-00 |
  |-----------|
  |  1-MAR-00 |
  |  1-MAR-00 |
  |  02/15/98 |
  |  12/01/98 |
  |  1-AUG-00 |
  |-----------|
  | 8/15/1998 |
  | 8/15/1998 |
  | 6/30/1998 |
  | 6/30/1998 |
  |  7/1/1999 |
  +-----------+

Is there an ado-file or function out there that can help fix this?  We have
something called chgdate, but it assumes that all the variables are in
"xx/xx/xxxx" format and drops everything else.  My goal is to have 1
variable that has a date in the Stata date format.

Thank you!

Kate




Kate Rohrbaugh
Research Team Leader
Research and Special Studies
Independent Project Analysis, Inc.
44426 Atwater Drive
Ashburn, VA  20147
 
direct - 703.726.5465
front desk - 703.729.8300
fax - 703.729.8301
email - [email protected]
website - www.ipaglobal.com



*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index