Monday, February 27, 2006
st: looping through dates and keeping dates which are two years apart
I have a series of dates as follows
03nov1989 04jan1990 15feb1990 19feb1990 30aug1991 03sep1993 08aug1995 27feb1996 06aug1996 26feb1997 22aug1997 30sep1997 18feb1998 11aug2000
I want to keep dates if they are two years apart. I tried the command: drop if date-date[_n-1]<= 730
03nov1989 03sep1993 11aug2000
This is not the result I want as you will see that the date 27feb1996 is more than 730 days apart from 03sep1993 but the command actually looks at 03sep1993 and the date previous to that and as the previous date is 27feb1996 (less than 2 years apart) drops it.
The logic of what I want to do is this..but I don't know how to code it..!!!!
1. Start with the first date.
2. See if the next date is more than 730 days from it. if its less than 73o days away from the first date drop it.
3. If it is more than 730 days away keep it and
4. Now this date becomes the reference date and the difference between this date and the next is calculated and so on
* * 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/
Links to this post: