Statalist


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

AW: st: Re: Changing Prefix of Variable Name


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: Re: Changing Prefix of Variable Name
Date   Mon, 2 Nov 2009 13:37:38 +0100

<> 

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: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Eric Booth
Gesendet: Montag, 2. November 2009 13:33
An: statalist@hsphsun2.harvard.edu
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
ebooth@ppri.tamu.edu
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
> epw@mail.med.upenn.edu
> *
> *   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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index