Statalist The Stata Listserver


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

Re: st: HELP! recoding string or long variable into some "text" format


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: HELP! recoding string or long variable into some "text" format
Date   Tue, 15 May 2007 08:35:24 +0900

Marcos Feldman wrote:

can anyone help me figure this out? i am
trying to create a new variable based on an existing variable
containing zoning codes. i actually have two variables with the zoning
codes, one is string format another is long format. the codes (values)
in both look like this: 0001, 0004, 0072, 9001, etc. I want to replace
these codes with their descriptors, e.g., convert 0001 to
"single-family residential," and so on.

thus far stata has not allowed me to recode either string or long variables
into "text".

for example, for the long variable "PRI_ZONE" i used the command,
    recode test ("0002"="MULTIFAMILY DUPLEX") ("0100"="SINGLE FAMILY
RESIDENCE").... [many more such commands...]
but the response was "unknown el MULTIFAMILY DUPLEX in rule"
is
recoding into text not allowed? have i just written the rules
incorrectly? is there some other way to accomplish this transformation?

--------------------------------------------------------------------------------

It sounds as if you have a list for Florida "County Land Use Code" (CLUC),
but your analysis dataset has only a variable of the code numers (as
strings).  This sounds like a job for -merge-.  I wouldn't try manually
replacing the string code numbers with the descriptors if I had the look-up
table downloaded from Tallahassee or your county's zoning board.

1. Import your cross-reference list into Stata using -infile-, -infix-,
-odbc load-, or -insheet- as appropriate; -sort- on the code number and save
as a Stata dataset, retaining the string datatype for the code number.
Use -tostring , replace format(%04.0f)- if needed for the latter.

2. Then -use- your analysis dataset, -sort- this dataset, too, on the code
number and,

3. -merge- on the code number.

4. Use -tabulate _merge- to inspect for mismatches (analogous to left outer
join, right outer join and inner join).

Type "help merge" on the command line for more information.

Joseph Coveney

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