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]

[no subject]



As presented, -date- lacks a final digit.

Regardless, only going back to the original date strings and
re-calculating will solve this.
Nick
[email protected]


On 6 August 2013 16:56, Dherani, Mukesh <[email protected]> wrote:
> Thanks Nick. Yes, date was messed up somehow (mystery to me).  Below is date in as I could see (date), after format %d (afterformat) and gen date1=date.  This is why I was trying to view month and year after format.
>
>
> date            afterformat     date1
> 19/02/200       19/02/2003      81
> 17/01/200       17/01/2003      24
> 03/01/200       03/01/2003      9
> 23/01/200       23/01/2003      46
> 03/01/200       03/01/2003      9
> 07/01/200       07/01/2003      97
> 10/01/200       10/01/2003      29
> 18/07/200       18/07/2003      44
> 25/04/200       25/04/2003      100
> 05/04/200       05/04/2004      35
> 03/01/200       03/01/2003      9
> 19/06/200       19/06/2003      51
> 13/06/200       13/06/2003      4
> 19/08/200       19/08/2003      102
> 30/05/200       30/05/2003      118
> 29/09/200       29/09/2003      38
> 26/12/200       26/12/2002      72
> 08/01/200       08/01/2003      73
> 26/09/200       26/09/2003      25
> 17/01/200       17/01/2003      24
> 20/06/200       20/06/2003      10
> 10/02/200       10/02/2004      125
> 25/08/200       25/08/2003      109
> 16/05/200       16/05/2003      42
> 20/02/200       20/02/2003      39
> 09/02/200       09/02/2004      85
> 14/05/200       14/05/2004      58
> 08/07/200       08/07/2003      7
> 16/07/200       16/07/2003      84
> 14/12/200       14/12/2003      31
>
>
> BW,m
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
> Sent: 06 August 2013 16:18
> To: [email protected]
> Subject: Re: st: date function
>
> Working backwards:
>
> 1. Changing the format of anything has precisely no effect on what is stored, only on what is displayed. Thinking that "format" means "display format" and nothing else is crucial to understanding this.
> There is a Tip spelling this out in excruciating detail.
>
> http://www.stata-journal.com/article.html?article=dm0067
>
> So no machinations with -format- will solve this problem.
>
> 2. My guess is that your -date- variable is thoroughly messed up and it was produced in some wild way. I guess further that you used
> -encode- to convert a string variable into a numeric variable with labels. If you look at the dates that Stata thinks are stored they are all daily dates in 1960 and, moreover, the first such date in your sample is
>
> 03/01/2003         10           1              1960
>
> and the last such date is
>
> 25/04/2003         10           4              1960
>
> which is consistent with this guess. That is, the string "03/01/2003"
> is the first alphabetically (alphanumerically) and the string "25/04/2003" is the last alphabetically in this sample and they, and the other dates, have been mapped to numbers. -encode- is totally clueless about dates and faced with dates it can only treat them like any other set of strings, the first alphabetically being mapped to 1, the second to 2, and so forth, regardless of the strings' meaning or content.
>
> So, you must go back and recalculate your dates, using the -date()- function. Ironically, or otherwise, this is the title of your post, but you appear not to have used it.
>
> As said, these are guesses, but I'd call them informed guesses.
>
> The document to read first, second and third on dates is the help.
> -help dates and times-.
>
> Nick
> [email protected]
>
> On 6 August 2013 15:52, Dherani, Mukesh <[email protected]> wrote:
>
>> I have a problem getting my date variable sorted.  I have Date
>> variable in = my data (float) and I want month and year extracted
>> using
>>
>> gen month = month(date)..... same for day and yr.
>> However, I am getting incorrect values for month and year (even day).
>> I have also tried formatting month and year to %m and %ty, but to no avail.
>> Any help appreciated... I am using Stata 10. [no luck with FAQ so far]
>>
>>
>> date               day         month            yr
>> 19/02/2003         22           3              1960
>> 17/01/2003         25           1              1960
>> 03/01/2003         10           1              1960
>> 23/01/2003         16           2              1960
>> 03/01/2003         10           1              1960
>> 07/01/2003         7              4              1960
>> 10/01/2003         30           1              1960
>> 18/07/2003         14           2              1960
>> 25/04/2003         10           4              1960
>> 05/04/2004         5              2              1960
>> 03/01/2003         10           1              1960
>> 19/06/2003         21           2              1960
>> 13/06/2003         5              1              1960
>> 19/08/2003         12           4              1960
>>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index