Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: -encode- with predetermined sorting
From
"Impavido, Gregorio" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: -encode- with predetermined sorting
Date
Thu, 7 Jun 2012 16:45:15 -0400
Dear All,
I have the following dataset:
. list
+--------+
| a b |
|--------|
1. | 10 a |
2. | 40 b |
3. | 30 c |
4. | 20 d |
+--------+
If I encode b and generate c, I get:
. list *, nolabel
+-------------+
| a b c |
|-------------|
1. | 10 a 1 |
2. | 40 b 2 |
3. | 30 c 3 |
4. | 20 d 4 |
+-------------+
Now, I want to have a different sort order for c, say as a function of a:
. list *, nolabel
+-------------+
| a b c |
|-------------|
1. | 10 a 1 |
2. | 40 b 4 |
3. | 30 c 3 |
4. | 20 d 2 |
+-------------+
Is there a more rapid way than the following to obtain what I want?
sort a
gen c = _n
forvalues i=1/4 {
label define lblname `i' "`: di b[`i']'", add
}
label values c lblname
*
* 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/