Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: leap years


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: leap years
Date   Thu, 15 Jan 2004 16:27:22 -0500

At 06:30 PM 1/15/2004 +0000, Nick Cox wrote:
2004 is a leap year. This raises a small Stata problem,
how to determine if a year is a leap year using Stata
syntax.

[...]

In Stata: suppose -year- is a variable. An indicator
1 for leap year and 0 otherwise is then
given by

(mod(year,4) == 0 & mod(year,100) != 0) | mod(year,400) == 0

as -mod(,)- provides the remainder left over from division.

The nested -cond()- solution, to please David Kantor, is

        cond(mod(year,400) == 0, 1,
          cond(mod(year,100) == 0, 0,
          cond(mod(year,4)   == 0, 1,
          0)))

[...]
Thanks for citing me. But this is one instance where I would opt for the former expression, since we are getting values of 0 or 1 only.

-- David

David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
410-516-5404

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index