Statalist


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

AW: st: AW: Creating non-overlapping events


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: st: AW: Creating non-overlapping events
Date   Tue, 24 Nov 2009 17:54:15 +0100

<> 

" First, I use the  -by- groups companyname AND name. I need both since
the same name can appear in a different company,as well. I thought
that implementing by groups would be easier but with your solution it
not possible- or, I dont know how to handle it..."


-bysort- works well in this setup, but the -in- qualifier is not available then, so you have to use -inrange()- here. See NJC`s http://www.stata-journal.com/article.html?article=pr0004



*************
bys companyname name:  /* 
*/ gen byte overlap= /*
*/ eventdate2 < postdays2[_n-1]  /*
*/ if inrange(_n, 2, _N)
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Kaspar Dardas
Gesendet: Dienstag, 24. November 2009 17:43
An: [email protected]
Betreff: Re: st: AW: Creating non-overlapping events

Hi Martin,


thanks for your promt answer. However, this won't solve my problem.
Since I  did not describe the problem properly its all on me. Your
solution is perfect for what I have described.

First, I use the  -by- groups companyname AND name. I need both since
the same name can appear in a different company,as well. I thought
that implementing by groups would be easier but with your solution it
not possible- or, I dont know how to handle it...

Furthermore, a situation might appear where two overlaps exist. (see
trade 6 and 7). Trade 6 and 7 have to be dropped. However trade 8 is
fine since it does not interfere with trade 5. I dont think your
solution will caputre this, or will it?

> 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 B" "Michael, Ham" 06-Aug-04 26-Aug-04
> 6 "Company B" "Michael, Ham" 07-Aug-04 27-Aug-04
> 7 "Company B" "Michael, Ham" 15-Aug-04 02-Sep-04
> 8 "Company B" "Michael, Ham" 28-Aug-04 08-Sep-04


Thanks & best,

Kaspar


2009/11/24 Martin Weiss <[email protected]>:
>
> <>
>
> 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: [email protected] [mailto:[email protected]] Im Auftrag von Kaspar Dardas
> Gesendet: Dienstag, 24. November 2009 16:08
> An: [email protected]
> 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/
>

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