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

Re: st: dates and Stata

From   "Keith Dear (home)" <>
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
datecount sept 15 28jan1997 17sep2002
datecount Feb 2  28jan1997 17sep2002
datecount february 29 28jan1997 17sep2002


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

CRICOS provider #00120C

*   For searches and help try:

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