Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Converting letters to numbers


From   "Clive Nicholas" <[email protected]>
To   [email protected]
Subject   Re: st: Converting letters to numbers
Date   Wed, 28 Jan 2004 01:58:06 -0000 (GMT)

Phillip,

Michael Blasnik suggested -subinstr- to me off the list.

Any incorrect running of it was down to me!

Thanks for your reply. I didn't try -nolabel- of any of your other
solutions, so I'll try them.

C.

> I ran Joseph's code against Clive's data and it appeared to deliver what
> Clive wants (if I understand Clive correctly).
>
> Clive, did you -list- the data resulting from Joseph's code with the
> -nolabel- option, to show the real, underlying form of the data ?
>
> I have not seen Michael Blasnik's contribution to this thread on the list,
> so I cannot comment on details, but note that -subinstr() is a *function*,
> not a command, so Stata quite rightly objects if you type:
>
> . subinstr(...)
>
> apart form the incorrect specification of the argument that you supplied.
> (see help strfun)
>
> Even if used correctly as a function  < gen newvar = subinstr(...) >   I
> think the complexity of the code would probably equal or exceed that of
> Joseph's suggestion, as you might need to use some nested -cond()-
> functions to sequentially look at the string (is it "c" or "d" or l" or
> "n"
> ?) and make the appropriate substitution, and you will still need to loop
> through the party? variables.
>
>
>
> Phil
>
>
>
> At 12:42 AM 28/01/2004 +0000, you wrote:
>>Joseph Coveney wrote:
>>
>> > How about something like this?
>> >
>> > label define Parties 1 c 2 d 3 l 4 n
>> > forvalues i = 1/4 {
>> >     encode party`i', generate(Party`i') label(Parties)
>> >     drop party`i'
>> >     rename Party`i' party`i'
>> > }
>>
>>OK, it ran, but the end-result still displays letters rather than the
>>numeric (and real) values I want them to represent.
>>
>>I should be a bit more specific in explaining what I've tried to overcome
>>this difficulty (I'm on v8.2). I've used -encode-, as in
>>
>>. encode party1, gen(winner)
>>
>>but this merely produced variables with the same characters. Stata won't
>>accept a simple -recode- such as
>>
>>. recode party c=1
>>
>>Michael Blasnik did suggest -subinstr-, but I couldn't work out how to
>>action this command. Every time I tried it, including
>>
>>. subinstr(c,l,d,1,2,3)
>>
>>I kept getting an 'unrecognized command' error (oddly). There has to be a
>>simple solution to this simple problem!
>>
>>CLIVE NICHOLAS        |t: 0(44)191 222 5969
>>Politics Building     |e: [email protected]
>>School of Geography,  |f: 0(44)870 126 2421
>>  Politics & Sociology |
>>University of         |
>>  Newcastle-upon-Tyne  |
>>Newcastle-upon-Tyne   |
>>NE1 7RU               |
>>United Kingdom        |http://www.ncl.ac.uk/geps
>>*
>>*   For searches and help try:
>>*   http://www.stata.com/support/faqs/res/findit.html
>>*   http://www.stata.com/support/statalist/faq
>>*   http://www.ats.ucla.edu/stat/stata/
>
> Philip Ryan
> Associate Professor,
> Department of Public Health
> Associate Dean (Information Technology)
> Faculty of Health Sciences
> University of Adelaide 5005
> South Australia
> tel 61 8 8303 3570
> fax 61 8 8223 4075
> http://www.public-health.adelaide.edu.au/
> CRICOS Provider Number 00123M
> -----------------------------------------------------------
> This email message is intended only for the addressee(s)
> and contains information that may be confidential and/or
> copyright. If you are not the intended recipient please
> notify the sender by reply email and immediately delete
> this email. Use, disclosure or reproduction of this email
> by anyone other than the intended recipient(s) is strictly
> prohibited. No representation is made that this email or
> any attachments are free of viruses. Virus scanning is
> recommended and is the responsibility of the recipient.
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>


CLIVE NICHOLAS        |t: 0(44)191 222 5969
Politics Building     |e: [email protected]
School of Geography,  |f: 0(44)870 126 2421
 Politics & Sociology |
University of         |
 Newcastle-upon-Tyne  |
Newcastle-upon-Tyne   |
NE1 7RU		      |
United Kingdom	      |http://www.ncl.ac.uk/geps
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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