Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: forvalues within foreach?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: forvalues within foreach?
Date   Tue, 11 May 2004 23:39:04 +0100

Good. 

Now -spellsplit- does well what 
it claims to do, but it changes
the data structure more than seems
essential for some purposes. Having
got interested in the problem, 
I have written a -disjoint- program 
which generates a new variable 
which is a pseudo-end variable 
for accounting purposes. 

In a simple case, with overlapping
and also enclosed spells, 

. l

     +------------------+
     | id   start   end |
     |------------------|
  1. |  1       3     6 |
  2. |  1      12    17 |
  3. |  1      13    14 |
  4. |  1      13    22 |
  5. |  1      14    20 |
     |------------------|
  6. |  2       2     8 |
  7. |  2       3    12 |
  8. |  2      12    15 |
  9. |  2      13    16 |
 10. |  2      18    28 |
     +------------------+

we generate a pseudo-end 

. disjoint start end, id(id) gen(end2) 

That pseudo-end is missing whenever
a spell adds no information to what 
we know already: 

. l

     +-------------------------+
     | id   start   end   end2 |
     |-------------------------|
  1. |  1       3     6      6 |
  2. |  1      12    17     12 |
  3. |  1      13    14      . |
  4. |  1      13    22     22 |
  5. |  1      14    20      . |
     |-------------------------|
  6. |  2       2     8      2 |
  7. |  2       3    12     11 |
  8. |  2      12    15     12 |
  9. |  2      13    16     16 |
 10. |  2      18    28     28 |
     +-------------------------+

so we could work with this subset 

. l id start end2 if end2 < . 

     +-------------------+
     | id   start   end2 |
     |-------------------|
  1. |  1       3      6 |
  2. |  1      12     12 |
  4. |  1      13     22 |
  6. |  2       2      2 |
  7. |  2       3     11 |
     |-------------------|
  8. |  2      12     12 |
  9. |  2      13     16 |
 10. |  2      18     28 |
     +-------------------+

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of
> [email protected]
> Sent: 11 May 2004 23:20
> To: [email protected]
> Subject: RE: st: RE: forvalues within foreach?
> 
> 
> Many Thanks Nick!!
> The combination of your code with Edwin Leuven's -spellsplit- 
> solved my problem.
> -Clint
> 
> On 11 May 2004 at 22:11, Nick Cox wrote:
> 
> > I just wrote 
> > 
> > > Overlapping records are clearly a problem 
> > > for this code. It just adds up blindly. 
> > 
> > ...  
> > 
> > > More important note: Somebody must 
> > > have solved this problem before!
> > 
> > Indeed, 
> > 
> > . findit overlap 
> > 
> > points to -spellsplit- by Edwin Leuven. 
> > 

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