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]
Re: st: Formatting months error
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Formatting months error
Date
Thu, 7 Mar 2013 10:58:13 +0000
Misunderstandings about date formats have been explained many times on
the list e.g.
http://www.stata.com/statalist/archive/2013-01/msg00893.html
http://www.stata.com/statalist/archive/2013-01/msg01350.html
and I wrote a Tip about it
Nicholas J. Cox
Stata tip 113: Changing a variable's format: What it does and does not mean
The Stata Journal
Volume 12 Number 4: pp. 761-764
When you change the -format- you don't change the date. You just
change the instructions to Stata on how to think about a number.
18628 _could_ be a daily date: it is 16 jan 2011 to Stata. It could be
a monthly date, May 3512. That is what %tm implies: you are saying to
Stata "this is a monthly date, so display it accordingly".
Changing the format just changes what is displayed: it doesn't change
what is stored.
You need a conversion function, in your case -mofd()-,
or
a display -format- that starts %td and includes month
depending on what you want.
Nick
On Thu, Mar 7, 2013 at 10:41 AM, Paul O'Brien <[email protected]> wrote:
> I cannot find the bit in the manuals that sorts this out for me. I get the wrong month when I format for month with %tm.
>
> . gen date=18628
>
> . format date %td
>
> . l
>
> +-----------+
> | date |
> |-----------|
> 1. | 01jan2011 |
> +-----------+
>
> . format date %tm
>
> . l
>
> +--------+
> | date |
> |--------|
> 1. | 3512m5 |
> +--------+
>
> What am I doing wrong?
*
* 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/