Statalist


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

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


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: AW: Problems with %tw when date() is used to create a date variable
Date   Fri, 6 Nov 2009 10:40:59 +0100

<> 

See the conversion in action in the last line...

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

inp str10 dates 
"12/31/1974"
end

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

list, noobs 

//wrong
di %tw myDate
//correct
di %tw wofd(myDate)
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Freitag, 6. November 2009 10:37
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: Problems with %tw when date() is used to create a date
variable


<> 

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: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Joachim
Landström
Gesendet: Freitag, 6. November 2009 10:37
An: statalist@hsphsun2.harvard.edu
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/


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index