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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Problem with the time


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Problem with the time
Date   Wed, 13 Apr 2011 16:18:25 +0100

Right and wrong.

-year()- expects an argument in days. So you are quite right on that.

But -- and this is fundamental -- in Stata a format is just how data
are displayed. It is not what the data are, or how they are stored.

A format is irrelevant to numeric operations, just relevant on display.

This is a very common confusion, perhaps because the word "format"
tends to be used in so many ways for different software and computing
purposes.

So, for example, here is a daily date with a format that shows only the year:

. di %td_CY  mdy(4,13,2011)
  2011

That is not perverse; it is not only possible but sometimes the answer
to a question.

Numeric data are not defined by their format! This might seem
pedantry, but it is common to see people imagining on this list that
changing a format changes a numeric value, and that is not true.

It is true that in something like string(1.234, format("%2.1f")) the
format determines the result, but in the more common case of numeric
data it is best to keep value and format separate in your mind.

Nick

On Wed, Apr 13, 2011 at 4:05 PM, Oliver Jones
<ojones@wiwi.uni-bielefeld.de> wrote:
> Hi,
> maybe the function year just can handle the format %td correctly?
>
> dis year(0)
>
> gives the expected result of 1960 which is Statas base year.
> And then
>
> dis year(366)
>
> gives the year 1961.
>
> But I can't help more...
>
> Best
> Oliver
>
> Am 13.04.2011 16:45, schrieb Guido Lüchters:
>>
>> Hi Statalist
>>
>> anybody knows
>>
>> why
>>
>> gen x=year(ym(1951,1))
>>
>> gives
>> 1959 ?
>>

*
*   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   |   Site index