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

Re: st: scripting question (_n)


From   austin nichols <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: scripting question (_n)
Date   Fri, 26 Aug 2005 12:17:32 -0400

True, but "creat a unique number to identify each set from a-b" does
not uniquely identify the method of assigning an index variable when
"b" may occur serially.  My method assumes every instance of "b"
increments the index.  Even better might be
. gen long var2=1+sum(var1[_n-1]=="b") if !(var1[_n-1]=="b" & var1=="b")

to give, e.g.
    var1   index   var2  
       a       1      1  
       a       1      1  
       a       1      1  
       b       1      1  
       a       2      2  
       a       2      2  
       a       2      2  
       b       2      2  
       a       3      3  
       a       3      3  
       a       3      3  
       b       3      3  
       b       4      .  
       a       5      4  
       a       5      4  
       a       5      4  
       b       5      4  
       a       6      5  
       a       6      5  

forcing the user to make a separate choice about repeated "b" cases, such as
. replace var2= var2[_n-1] if mi(var2)

On 8/26/05, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> This assumes, I think, that "b" occurs only
> as singletons, true of the example Kelly
> gave but otherwise not explicit.
> 
> Nick
> n.j.cox@durham.ac.uk
> 
> austin nichols
> 
> > gen long index=1+sum(var1[_n-1]=="b")
> >

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