| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: looping through dates and keeping dates which are two years apart
From |
"David Harrison" <[email protected]> |
To |
<[email protected]> |
Subject |
st: RE: looping through dates and keeping dates which are two years apart |
Date |
Mon, 27 Feb 2006 10:45:56 -0000 |
One brute force way (i.e. doing exactly what you set out in your
numbered steps) is as follows:
local refdate = date[1]
gen byte dropflag = 0
forvalues i = 2/`=_N' {
if date[`i']-`refdate'<=730 {
replace dropflag = 1 in `i'
}
else {
local refdate = date[`i']
}
}
drop if dropflag
drop dropflag
There must be a more elegant way, but unless your dataset is really big
and/or you are going to do this often it is probably not worth the
effort to work it out...
Hope this helps
David
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Rajesh
Tharyan
Sent: 27 February 2006 10:19
To: [email protected]
Subject: st: looping through dates and keeping dates which are two years
apart
Hi,
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
this gives
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
Thanks
Rajesh
*
* 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/
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
*
* 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/