Bookmark and Share

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: replacement


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: replacement
Date   Tue, 16 Aug 2011 16:19:46 +0200

On Tue, Aug 16, 2011 at 3:51 PM, Gannaway Jack WWG HWWD  wrote:
>> I have a table where each observation has a letter as the value for a
>> number of the variables, e.g.
<snip>
>> For each variable, there is a unique set of numbers which correspond
>> to the letters:
<snip>
>> Can anyone explain a neat way of replacing all the letters with their
>> relevent numeric score?


I originally thought about using a -merge- strategy, though I am not
sure it is much better than using -replace-. As long as you do either
in a .do-file and save that .do-file and _not_ the data, either
solution should be easily reproducible, readable, check-able and
correctable.

*----------- begin example -------------
clear
input ///
str1 v1 n1 str1 v2 n2 str1 v3 n3
     a  0       a  0       a  0
     b  3       b  1       b  1
     c  5       c  2       c  5
     d  9       d  5       d  10
end	
tempfile mask
save `mask'

clear
input ///
Ob str1 v1 str1 v2 str1 v3
 1      a       a       b
 2      c       d       a
 3      b       c       b
 end

merge m:1 v1 using `mask', keepusing(n1)
assert _merge != 1	
drop if _merge == 2
drop _merge

merge m:1 v2 using `mask', keepusing(n2)
assert _merge != 1	
drop if _merge == 2
drop _merge

merge m:1 v3 using `mask', keepusing(n3)
assert _merge != 1	
drop if _merge == 2
drop _merge

list
*----------------------- end example ------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index