Thanks to Kit Baum, -vreverse- posted on SSC at the
end of last week has been revised to
add options to deal with an issue raised by Renzo
Comolli arising from prior use of -numlabel-.
-vreverse- requires Stata 8.
The remainder of this mail gives the details.
It is really only for those intrigued or concerned
by the problem.
====================================== details
Suppose you
. sysuse auto
. numlabel origin, add
The consequence is
. tab foreign
Car type | Freq. Percent Cum.
------------+-----------------------------------
0. Domestic | 52 70.27 70.27
1. Foreign | 22 29.73 100.00
------------+-----------------------------------
Total | 74 100.00
Now for some reason if you consider this coding
to be the wrong way round, and thus -vreverse-,
then this will be produced:
. vreverse foreign, gen(Foreign)
. tab Foreign
Car type | Freq. Percent Cum.
------------+-----------------------------------
1. Foreign | 22 29.73 29.73
0. Domestic | 52 70.27 100.00
------------+-----------------------------------
Total | 74 100.00
As Renzo pointed out, you might well consider
these value labels inappropriate, but how to
fix it? A tedious way would be
. numlabel origin, remove
. vreverse foreign, gen(Foreign)
. numlabel origin, add
but you can now remove the prefixes directly
(indeed without touching the original value
labels, even temporarily):
. vreverse foreign, gen(Foreign2) remove
. tab Foreign2
Car type | Freq. Percent Cum.
------------+-----------------------------------
Foreign | 22 29.73 29.73
Domestic | 52 70.27 100.00
------------+-----------------------------------
Total | 74 100.00
If you want this variable's value labels to have
numeric prefixes, that can be done in the normal way
. numlabel Foreign2, add
. tab Foreign2
Car type | Freq. Percent Cum.
------------+-----------------------------------
0. Foreign | 22 29.73 29.73
1. Domestic | 52 70.27 100.00
------------+-----------------------------------
Total | 74 100.00
where we can exploit the fact that by default
-vreverse- defines value labels with the same name
as the variable it creates.
=========================== even more details
Suppose that originally somebody used the -mask()-
option of -numlabel-:
. numlabel origin, add mask("[#] ")
. tab foreign
Car type | Freq. Percent Cum.
-------------+-----------------------------------
[0] Domestic | 52 70.27 70.27
[1] Foreign | 22 29.73 100.00
-------------+-----------------------------------
Total | 74 100.00
That's OK, so long as you specify what the mask is,
so -vreverse- knows how to remove it:
. vreverse foreign, gen(Foreign3) remove mask("[#] ")
. tab Foreign3
Car type | Freq. Percent Cum.
------------+-----------------------------------
Foreign | 22 29.73 29.73
Domestic | 52 70.27 100.00
------------+-----------------------------------
Total | 74 100.00
Nick
[email protected]
*
* 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/