Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Identify and Replace Values
From
Eric Booth <[email protected]>
To
"<[email protected]>" <[email protected]>
Subject
Re: st: Identify and Replace Values
Date
Mon, 12 Jul 2010 19:39:33 +0000
<>
You can use -tokenize- for each element in `others' :
**************!
clear
inp str10 (traded_model new_model)
"g1" "f1"
"g2" "f2"
"g3" "f3"
"g4" "f4"
"f1" "g4"
"f2" "f5"
"g4" "g5"
"g5" "aa aa"
end
levelsof traded_model, local(traded)
levelsof new_model, local(new)
local onlytraded : list traded - new
local onlynew : list new - traded
local others : list onlynew | onlytraded
****************
di `"`onlytraded'"'
di `"`onlynew'"'
di `"`others'"'
****************
token `"`others'"'
**shouldn't need to subinstr() the spaces**
** due to the compound quotes in the macros**
while "`1'"!="" {
di "`1'"
replace traded_model="OTHERS" if inlist(traded_model,"`1'")
replace new_model ="OTHERS" if inlist(new_model,"`1'")
macro shift
}
**************!
~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
On Jul 12, 2010, at 2:28 PM, Tobias Friedli wrote:
> This command worked perfect, all the Names are usable now. But the function still doesnt do what i want:
>
> levelsof traded_model, local(traded)
>>>>> levelsof new_model, local(new)
>>>>> local onlytraded : list traded - new
>>>>> local onlynew : list new - traded
>>>>> local others : list onlynew | onlytraded
>>>>> replace traded_model="others" if inlist(traded_model,"`others'")
>>>>> replace new_model ="others" if inlist(new_model,"`others'")
>
> For the last two commands i get "0 real changes made". It seems like "onlytraded" and "onlynew" are empty... (althought traded contains about 70 more Names than new.) I have to do some more testing with it. If anyone sees the mistake in the Code, please tell me.. Anyways thank you all very much for your fast responses, i really appreciate it!!
>
>
>
> On Mon, 12 Jul 2010 19:09:57 +0000
> Eric Booth <[email protected]> wrote:
>> <>
>> Try using -subinstr()-
>> replace var = subinstr(var, " ", "_", .)
>> ~ Eric
>> __
>> Eric A. Booth
>> Public Policy Research Institute
>> Texas A&M University
>> [email protected]
>> Office: +979.845.6754
>> On Jul 12, 2010, at 2:05 PM, Tobias Friedli wrote:
>>> Thanks. This would be exactly what i am looking for. But it seems like this command was introduced in Stata 11 and i am stil working with Stata 10. Can i download this function somehow, so i can use it in Stata 10? Or is there a similar function?
>>> On Mon, 12 Jul 2010 20:56:03 +0200
>>> "Martin Weiss" <[email protected]> wrote:
>>>> <>
>>>> ***********
>>>> h strtoname
>>>> ***********
>>>> HTH
>>>> Martin
>>>> -----Original Message-----
>>>> From: [email protected]
>>>> [mailto:[email protected]] On Behalf Of Tobias Friedli
>>>> Sent: Montag, 12. Juli 2010 20:35
>>>> To: [email protected]
>>>> Subject: Re: st: Identify and Replace Values
>>>> Thank you very much, it seems to work like a charm. Only Problem is, that the some Model-names contain spaces and then Stata says "invalid name". I know there is a command to relpace all the spaces by an underscore, but i can't find it anymore. Anybody knows this command? Thanks
>>>> On Mon, 12 Jul 2010 13:52:46 -0400
>>>> Jeph Herrin <[email protected]> wrote:
>>>>> how about
>>>>> levelsof traded_model, local(traded)
>>>>> levelsof new_model, local(new)
>>>>> local onlytraded : list traded - new
>>>>> local onlynew : list new - traded
>>>>> local others : list onlynew | onlytraded
>>>>> replace traded_model="others" if inlist(traded_model,"`others'")
>>>>> replace new_model ="others" if inlist(new_model,"`others'")
>>>>> hth,
>>>>> Jeph
>>>>> On 7/12/2010 12:18 PM, Hobst wrote:
>>>>>> Hello
>>>>>> I have a huge dataset containing automotive brand-swiching data. I have a
>>>>>> variable called traded_model and another variable called new_model. in order
>>>>>> to output a symmetric swiching matrix i need to identify all the expressions
>>>>>> that are eigther only in traded_brand or only in new_brand and replace
>>>> the
>>>>>> expression with "others". For example a model called "318d" exists in
>>>>>> traded_model but not in new_model, so all the "318d" should be replaced
>>>> by
>>>>>> "others".
>>>>>> Does anyone have an idea how i can programm that? I dont get it to work, and
>>>>>> doing it manually is close to impossible as there are more than 1000
>>>>>> different model names.
>>>>>> Any help is much appreciated, thank you.
>>>>> *
>> *=
*
* 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/