Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

RE: st: Basic Numeric to String Recoding


From   Eric Booth <ebooth@ppri.tamu.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Basic Numeric to String Recoding
Date   Mon, 6 Sep 2010 21:45:37 +0000

<>

 I used that order because that's how -encode- encodes "state2" when using "census.dta"; however, if you sort on "state2" before encoding, you will get proper alphabetic order (and you'll need to change the -label define- statement in my code accordingly).

________________________________________
From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Nick Cox [n.j.cox@durham.ac.uk]
Sent: Monday, September 06, 2010 4:35 PM
To: 'statalist@hsphsun2.harvard.edu'
Subject: RE: st: Basic Numeric to String Recoding

Eric's spirit is exactly right, but those over 40 were taught the alphabet....

"Alabama" comes before "Alaska", modulo Sarah Palin. "Arizona" also comes before "Arkansas".

Nick
n.j.cox@durham.ac.uk

Eric Booth

Something like this:

****************!
**set up**
sysuse census, clear
keep state2 pop
encode state2 ,  g(state3)
lab  li
**********

lab def fullstates 1 "Alaska" 2 "Alabama" 3 "Arkansas"  ///
 4 "Arizona" 5 "California" 6 "Colorado", modify
**and so on...


lab val state3 fullstates
lab li
li state3 state2 //<-- make sure these line up
****************!

~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754


On Sep 6, 2010, at 4:17 PM, Benhoen2 wrote:

> I am a new user - please forgive me.
>
> I have a list of numeric IDs for states (stateid) with abbreviated labels
> attached (stname). I would like to create a new string variable made us of
> the unabbreviated state names but based on the stateid variable.
>
> I have tried the following:
> 1) recode stateid (1="Alabama"), (2="Arkansas"), ..., generate(statename)
> 2) recode stateid (1="Alabama"), (2="Arkansas"), ..., strgen(statename)
> 3) generate state="Alabama" if stateid=1
>
> among other nonsensical permutations.  Is there any way to do this using
> recode, or something analogous?
>

*
*   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   |   Site index