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:00:27 -0000

This does not identify just first occurrences, which bw specified. 

Nick 
[email protected] 

Ashim Kapoor

I would do: -

Suppose your variable is called var

gen j=var
replace j="diathermy[1]" if j[_n+1]=="diathermy[2]" & j=="diathermy[2]"

Then j would have what you want.

I think this should do it.

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