Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: simple string to number data conversion


From   "Donald Braman" <[email protected]>
To   [email protected]
Subject   Re: st: simple string to number data conversion
Date   Wed, 18 Apr 2007 15:05:01 -0400

Fixed!  I didn't realize I had to list with the "nolabel" option...I
was looking at labels, not values. Thanks for the help! -Don

On 4/18/07, Donald Braman <[email protected]> wrote:
Thanks!  I see that encode depends on labeling which seems to like
number -> string labeling, but not the reverse. So this works:

label define statefips 1 AL 2 AK 4 AZ 5 AR 6 CA 8 CO 9 CT 10 DE 11 DC
12 FL 13 GA 15 HI 16 ID 17 IL 18 IN 19 IA 20 KS 21 KY 22 LA 23 ME 24
MD 25 MA 26 MI 27 MN 28 MS 29 MO 30 MT 31 NE 32 NV 33 NH 34 NJ 35 NM
36 NY 37 NC 38 ND 39 OH 40 OK 41 OR 42 PA 44 RI 45 SC 46 SD 47 TN 48
TX 49 UT 50 VT 51 VA 53 WA 54 WV 55 WI 56 WY 60 AS 66 GU 72 PR 78 VI

but this doesn't:

label define statefips AK 2 AL 1 AR 5 AS 60 AZ 4 CA 6 CO 8 CT 9 DC 11
DE 10 FL 12 GA 13 GU 66 HI 15 IA 19 ID 16 IL 17 IN 18 KS 20 KY 21 LA
22 MA 25 MD 24 ME 23 MI 26 MN 27 MO 29 MS 28 MT 30 NC 37 ND 38 NE 31
NH 33 NJ 34 NM 35 NV 32 NY 36 OH 39 OK 40 OR 41 PA 42 PR 72 RI 44 SC
45 SD 46 TN 47 TX 48 UT 49 VA 51 VI 78 VT 50 WA 53 WI 55 WV 54 WY 56

Using encode with the first version just gives me my string values again.

Don
--
Donald Braman
email: [email protected]



On 4/18/07, Richard Goldstein <[email protected]> wrote:
> try the -encode- command
>
> Rich
>
> Donald Braman wrote:
>
> > Hi folks,
> >
> > I have a variable that happens to be a string FIPS abbreviation and
> > would like to convert it into a numerical FIPS code (e.g., "AL" into
> > 1).
> >
> > I'm new to STATA, and all my attempts using recode, egen, destring,
> > etc. have failed. I'm sure it's easy, just can't seem to figure it
> > out.
> >
> > Help?
> >
>
> *
> *   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/
>


--
Donald Braman
phone: 202-994-0572
email: [email protected]
http://papers.ssrn.com/sol3/papers.cfm?abstract_id=968652
*
*   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