Bookmark and Share

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: Formatting months error


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
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 <paul.obrien@afe2.org.uk> 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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index