[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
When I compare myDate with the original string I find a one-to-one
correspondance such that the myDate shows the same date as do the original
string (i.e., when the original string is 12/31/1974, the myDate %td format
is 31dec1974). However when I instead format myDate as %tw I find a
completely different result. E.g., the example 12/31/1974 then becomes
2065w19. . . Something must be very wrong and I appreciate any suggestion to
solve this riddle.
The code is as below.
capture drop myDay myMonth myYear
generate myYear = substr(dates,7,10)
replace myYear = substr(dates,5,4) if length(dates)==8
replace myYear = substr(dates,6,4) if length(dates)==9
generate firstSlash = strpos(dates,"/")
generate myMonth = substr(dates,1,2) if length(dates) == 10
replace myMonth = substr(dates,1,2) if firstSlash == 3
replace myMonth = substr(dates,1,1) if firstSlash == 2
generate myDay = substr(dates,4,2) if length(dates) == 10
replace myDay = substr(dates,4,1) if length(dates) == 9 & firstSlash == 3
replace myDay = substr(dates,3,2) if length(dates) == 9 & firstSlash == 2
replace myDay = substr(dates,3,1) if length(dates) == 8 & firstSlash == 2
destring myMonth, replace
destring myYear, replace
destring myDay, replace
generate myDate = mdy(myMonth, myDay, myYear)
format myDate %td
capture drop firstSlash
Regards
Joachim
___________________________________________
Joachim Landstrom
Assistant Professor
Department of Business Studies
Uppsala University, Sweden
*
* 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–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |