Statalist


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

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


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

The key (and only) difficulty here seems to be identifying first
occurrences (and only those). 

How to tackle that is an FAQ: 

. search first occurrence


FAQ     . . . . . . . . . . . . . . . First and last occurrences in
panel data
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N.
J. Cox
        3/07    How can I identify first and last occurrences
                systematically in panel data?
                <http://www.stata.com/support/faqs/data/firstoccur.html>


You can tag successive occurrences like this 

gen noccur = sum(var == "diathermy[2]") 

The first occurrence is then defined by 

... if noccur == 1 & noccur[_n-1] == 0 

The FAQ explains how to apply this approach to panel data. If you don't
have panel data, there is no problem, as the code above should suffice. 

Nick 
[email protected] 

b. water
 
stata 8.2 xp pro, 
 
i have a var like this: 
 
monopolar
bipolar
bipolar
bipolar
monopolar
nodiathrm
diathermy[2]
diathermy[2]
bipolar
monopolar
diathermy[2]
diathermy[2]
.
. <- denotes missing
.
monopolar
diathermy[2]
diathermy[2]
.
.
 
what i want to achieve is for every first encountered diathermy[2] to be
changed to diathermy[1], while leaving the second occurence as
diathermy[2]. is this possible in stata? if it can be done, would
appreciate advice/help on how to achieve it. 
 

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