Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: Problems with %tw when date() is used to create a date variable


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Problems with %tw when date() is used to create a date variable
Date   Fri, 6 Nov 2009 10:36:35 +0100

<> 

Not a riddle! -format-ting does not change the underlying value of the date
variable, only how it is -display-ed. To switch from daily to weekly
frequency, you want to use the conversion functions, as in

*************
help dates_and_times, mark(converting)
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Joachim
Landström
Gesendet: Freitag, 6. November 2009 10:37
An: [email protected]
Betreff: st: Problems with %tw when date() is used to create a date variable

Hi all,
I have encountered a strange problem that I do not know how to solve of if
there is a bug somewhere. The problem is as follows. From a string value
(such as e.g., 12/31/1974) I create myDate using date. The string value
12/31/1974 thus becomes myDate value 5478. Finally I format the myDate value
as e.g., %td or %tw. 

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

generate myDate = date(dates, "MDY")
format myDate %td

I have also tested to use mdy() to create myDate (which takes a few more
lines of code) and find identical results.

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/


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