Statalist


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

Re: st: dates and Stata


From   "Keith Dear (home)" <[email protected]>
To   [email protected]
Subject   Re: st: dates and Stata
Date   Sat, 30 May 2009 13:00:12 +1000

Maybe like this?

cap prog drop datecount
prog datecount
   args month day start end
   loc month=upper(substr("`month'",1,3))
   scalar datecount=0
   forval d=`=d(`start')'/`=d(`end')' {
       loc thismonth=upper(ltrim("`:di %dm `d''"))
if "`month'"=="`thismonth'" & `day'==day(`d') scalar datecount=datecount+1
   }
   di as result datecount
end
datecount sept 15 28jan1997 17sep2002
6
datecount Feb 2  28jan1997 17sep2002
6
datecount february 29 28jan1997 17sep2002
1


Regards,
kd



Olexandr O. Vasetsky wrote:
Hi guys,

I am trying to calculate the number of certain day and month occurrences
between the two dates: e.g. calculating the number of September 15th's and
February 2nd's from 28-Jan-1997 to 17-Sept-2002.

any ideas will be appreciated


--
Dr Keith Dear
Senior Fellow
National Centre for Epidemiology and Population Health
ANU College of Medicine, Biology and Environment
Building 62, cnr Mills and Eggleston Roads
Australian National University
Canberra ACT 0200 Australia
T: 02 6125 4865
F: 02 6125 0740
M: 0424 450 396
W: nceph.anu.edu.au/Staff_Students/staff_pages/dear.php

CRICOS provider #00120C
http://canberragliding.org/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index