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 on April 23, and its replacement, statalist.org is already up and running.


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

st: RE: using encode to order string distances


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: using encode to order string distances
Date   Mon, 24 Oct 2011 18:28:49 +0100

You need to parse your strings and order on the numeric equivalent of the lower value. That will be sufficient because the upper values increase too, except that the open upper limit is implicit. 

Here is one way to do it. 

Suppose -sdist- is string variable with distances. 

gen pos = max(strpos(sdist, "-"), strpos(sdist, "+")) 

We look for "-" or "+".  

gen n1 = real(substr(sdist, 1, pos-1)) 
egen group = group(n1) 
labmask group, values(sdist)

where -search labmask- will point to download locations. 

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

Tim Evans

I have distances stored in strings like:

0-9
10-19
20-29
30-39


up to 
90-99
100+

I want to encode these to keep the current values as labels and replace the numbers behind them as 1-12.

When I encode and generate a new variable I end up with 100+ as the 3rd value rather than the 12th value.

How can I force encode to make sure 100+ is the 12th and not the 3rd value.

I'm using 

encode nearestcentre, generate(NRCENT)


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