Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: date conversion
Nick Cox <firstname.lastname@example.org>
RE: st: date conversion
Fri, 27 May 2011 10:57:25 +0100
Thanks for this. You can now
. format date %td
Alternatively, use any other congenial format.
Thank Nick and Maarten!
Nick! I have silently read many of your posts and came to the same
conclusion that I should have read help files before taking times of
other experts but you know one misses things unintentionally as I did
in this very basic data manipulation. I am grateful to you always for
your constructive guidance adding always to my knowledge of using
I did the following and came with the new date variable which is now a
numeric serries but having missing entries for the missing dates which
I can use equally as my day variable. The resultant and original dates
are now after changing the format of day variable in Excel which I
think can be done in Stata.
. generate date = date(day, "MDY")
. li day date in 1/10
| day date |
1. | December 31, 2010 18627 |
2. | December 30, 2010 18626 |
3. | December 29, 2010 18625 |
4. | December 28, 2010 18624 |
5. | December 27, 2010 18623 |
6. | December 24, 2010 18620 |
7. | December 23, 2010 18619 |
8. | December 22, 2010 18618 |
9. | December 21, 2010 18617 |
10. | December 20, 2010 18616 |
I have the desired results in further analysis which became possible
after this conversion only. Thank you very much Nick and Maarten and
hope to have your guidance.
On 27 May 2011 13:34, Nick Cox <email@example.com> wrote:
> You need to get in the habit of using the help to sort out well
> documented issues like these.
> 1. -tsset- requires numeric variables. If you tried to -tsset- with a
> string variable, that won't work and you will have received an error
> message to that effect.
> 2. -encode- just maps string variables to integers 1 up and as you say
> throws away the specific date information except insofar as it is
> recorded in value labels.
> 3. Conversion of dates in string form can be achieved using the
> -date()- function; see -help dates_and_times-. Your example is
> ambiguous as between MDY and DMY, but one of
> gen ndate = date(date, "MDY")
> gen ndate = date(date, "DMY")
> will be the answer in Stata 11. (In Stata 10, and earlier, arguments
> would "mdy" or "dmy". )
> On Fri, May 27, 2011 at 4:40 AM, Muhammad Anees <firstname.lastname@example.org> wrote:
>> Sorry to post might be not in the right place but my question somehow
>> related to the conversion of dates too. I have date in the format
>> 1/1/2008 and it is in the string format. When I tsset my data using
>> the string variable it is not working as usual. Now I have encoded my
>> date variable using encode date, gen(day) which generates new day
>> variables but when I explore the data all the day variable has been
>> re-ordered and what reasons works behind it. Also how can I expect to
>> have to have both date and day side by side and no ordering to occure
>> when I convert date to day or otherwise.
* For searches and help try: