<>
Elisabeth`s initial query is also compatible with the simplest solution of
all:
*************
clear*
inp str10 var1
"alpha"
"beta"
"gamma"
end
replace var1="1lpha" /*
*/ if var1=="alpha"
l, noo
*************
She really needs to come back to the list and specify the conditions under
which some part of her string variable should be turned into something
else...
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Eric Booth
Gesendet: Montag, 2. November 2009 13:33
An: [email protected]
Betreff: Re: st: Re: Changing Prefix of Variable Name
If Elisabeth really wants to change a prefix on the observations in a
variable (not the variable name itself using -rensfix-), she can use -
subinstr()- or -regexm()- for more complex substitutions, e.g.,
***
clear
input str10 var1
alpha
beta
delta
apple
arch
bean
aaaaaa
end
//change starting "a" only
gen pos = strpos(var1, "a")
replace var1 = subinstr(var1, "a", "1", 1) if pos==1
drop pos
*****
Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
On Nov 2, 2009, at 6:16 AM, E. Paul Wileyto wrote:
> Search Stata help:
>
> search rensfix, all
>
> It's a user-written command that is very useful for changing
> prefixes and suffixes.
>
>
>
> Elisabeth Müller wrote:
>> Hello,
>>
>> does anybody know how to change the prefix of an observation (not
>> variable)? E.g. if I want to change the observation "alpha" into
>> "1lpha"?
>>
>> Thanks
>>
>
> --
> E. Paul Wileyto, Ph.D.
> Assistant Professor of Biostatistics
> Tobacco Use Research Center
> School of Medicine, U. of Pennsylvania
> 3535 Market Street, Suite 4100
> Philadelphia, PA 19104-3309
>
> 215-746-7147
> Fax: 215-746-7140
> [email protected]
> *
> * 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/
*
* 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/
*
* 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/