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]

Re: st: Problem with the time


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Problem with the time
Date   Wed, 13 Apr 2011 16:38:50 +0100

I cannot comment on "excel", presumably a reference to MS Excel.

But you have the main point.

The issue is no more than that years, months, days, ... are different
units and that you have to pay attention to what functions expect as
input.

What -year()- does is clearly documented

           -------------------------------------------------------------
                                            Result if d = td(05jul1972)
            Function         Returns            (i.e., d = 4,569)
            -------------------------------------------------------------
            year(d)          calendar year            1972"

The fact is that many people would complain bitterly if Stata didn't
allow these different ways of measuring time -- and rightly so. So,
the price of supporting that is a menagerie of conversion functions.

Me too: I don't use dates that often and I can only remember a few of
these functions. I have to look the others up every time I want them.

Nick

On Wed, Apr 13, 2011 at 4:27 PM, Guido Lüchters
<[email protected]> wrote:
> Many many thanks
>
> completely understood
>
> So the internal integer is not an absolute value
> like date(1951,12,31) from excel
> rather than in the metric of the number-to-date-unit: i.e. "month" in
> case of ym()
> so the units must fit like
>
> yofd(mdy(1,1,1951))

> On Wed, Apr 13, 2011 at 5:03 PM, Nick Cox <[email protected]> wrote:
>> Yes.
>>
>> ym(1951,1) is -108, that many months before the origin at ym(1960,1) == 0.
>>
>> But year() expects an argument in days. If you feed it -108, that is a
>> daily date within 1959, which is what you got.
>>
>> So, you need to map from months to days first, as in
>>
>> . di year(dofm(ym(1951,1)))
>> 1951
>>
>> There may be a simpler method of doing it, but that one works.
>>
>> Compare also
>>
>> . di yofd(mdy(1,1,1951))
>> 1951
>>
>> Nick
>>
>> On Wed, Apr 13, 2011 at 3:45 PM, Guido Lüchters
>> <[email protected]> wrote:
>>>
>>> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index