Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Re: looping through dates and keeping dates which are two years apart- thanks !


From   "Rajesh Tharyan" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: looping through dates and keeping dates which are two years apart- thanks !
Date   Mon, 27 Feb 2006 20:14:14 -0000

Thanks Michael and David...both the codes work brilliantly, 

That does solve a major headache... I was reading up on some tutorial notes
on loops and programming but I couldn't get my head round the 
If else loop...

Thanks
rajesh


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Michael Blasnik
Sent: 27 February 2006 13:23
To: [email protected]
Subject: st: Re: looping through dates and keeping dates which are two years
apart

I think this should do what you want.

sort date
gen days=date-date[_n-1]
qui count if days<730
while r(N)>0 {
drop if days<730
replace days=date-date[_n-1]
qui count if days<730
}

Michael Blasnik
[email protected]

----- Original Message ----- 
From: "Rajesh Tharyan" <[email protected]>
To: <[email protected]>
Sent: Monday, February 27, 2006 5:18 AM
Subject: st: looping through dates and keeping dates which are two years 
apart


<snip>
> 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/

*
*   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