Statalist


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

RE: st: data management - changing every 1st encountered of a str data content of a var


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: data management - changing every 1st encountered of a str data content of a var
Date   Tue, 6 Jan 2009 20:19:11 -0000

This different question I think falls under the heading of a spell
problem. Here a "spell" just means any run or sequence of identical
conditions. 

As mentioned just now, a detailed discussion of technique is available
in 

SJ-7-2  dm0029  . . . . . . . . . . . . . . Speaking Stata: Identifying
spells
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N.
J. Cox
        Q2/07   SJ 7(2):249--265                                 (no
commands)
        shows how to handle spells with complete control over
        spell specification

Independently of that, the program -tsspell- from SSC is a canned tool
for tackling several such problems. The help file contains several
worked examples. 

Nick 
[email protected] 

Ashim Kapoor

This dataset has brought a question to my mind.

I want to do : -

egen j=group(var) BUT I do not want the group to SORT var, I only want
consecutive groups to have the same value for j  ( this is what is
needed in the original question )

for example I would want the FIRST paired occurance of diathermy[2] to
be ONE group and the 2nd paired occurance of diathermy[2] to be
another group.

How would I do that ?

Here is a long way to do it!

egen j1=group(var1)
gen j2=_n
gen j3=j2
replace j3=j3[_n-1] if j1==j1[_n-1]

And then I would have the same group number j3 for same consecutive
items in var1. but I guess someone would have a variant of -egen
group- which DOES NOT do sorting?

Any comments ?


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