Statalist


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

st: AW: Creating non-overlapping events


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: Creating non-overlapping events
Date   Tue, 24 Nov 2009 16:27:30 +0100

<> 

No sign so far of which -by- groups you want, although I can see that they are relevant here. For the simple example, this is possible code:



*************
clear*

inp byte trade companyname:mylab name:mylab2  /* 
*/  str10(eventdate postdays), auto
1 "Company A" "Margetts, Rob" 14-Feb-03 06-Mar-03
2 "Company A" "Margetts, Rob" 17-Feb-03 09-Mar-03
3 "Company A" "Margetts, Rob" 14-Nov-03 04-Dec-03
4 "Company A" "Margetts, Rob" 14-May-04 03-Jun-04
5 "Company A" "Margetts, Rob" 06-Aug-04 26-Aug-04
end

compress

gen eventdate2=date(eventdate, "DM20Y")
format eventdate2 %tdMonth_DD,_CCYY
gen postdays2=date(postdays, "DM20Y")
format postdays2 %tdMonth_DD,_CCYY

drop eventdate postdays

gen byte overlap= /* 
*/ eventdate2 < postdays2[_n-1]  /* 
*/ in 2/`=_N'

//not just "overlap" as missing in first obs
drop if overlap==1

list, noobs
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Kaspar Dardas
Gesendet: Dienstag, 24. November 2009 16:08
An: statalist@hsphsun2.harvard.edu
Betreff: st: Creating non-overlapping events

Hello together,

I have the following problem. I need to create a non-overlapping event
data set. I have two date variables 1st: "eventdate" which is the
start of the event and 2nd: "postdays", which is the end of the event.
 The length of the event is exactly 20 days (which is, of course, the
difference between "eventdate" and "postdays"). If two events overlap
(which happens in trade 1 and 2, in the example below)  I only take
the first event and drop the 2nd (trade 2).
How can I do this in Stata? I have about 140000 trades, several
thousands companies etc....

trade         companyname                  name         eventdate
  postdays
1               Company A             Margetts, Rob      14-Feb-03
  06-Mar-03
2                Company A            Margetts, Rob       17-Feb-03
   09-Mar-03
3                Company A            Margetts, Rob      14-Nov-03
   04-Dec-03
4                Company A            Margetts, Rob       14-May-04
 03-Jun-04
5                 Company A           Margetts, Rob         06-Aug-04
   26-Aug-04



Many thanks for any help in advance!


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


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