Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: -numlabel- and -vreverse-


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: -numlabel- and -vreverse-
Date   Mon, 1 Sep 2003 09:28:52 +0100

Renzo Comolli

> On
> http://www.stata.com/statalist/archive/2003-08/msg00582.html
> Nick Cox writes "It is the user's responsibility to
> consider whether the
> copied variable label and characteristics
> also apply."
>
> In particular I want to draw the attention to the
> interaction between -numlabel- and -vreverse-
> If you first -numlabel label, add- and after -vreverse varname,
> generate(newvar)-, then the numbers in the lables will be
> wrong for newvar.
> The -vreverse- generates a new lable with the same name as
> newvar, to my
> (very modest) experience it is not possible to subsequently
> remove the
> numbers from the new lable.
>
> So (at the moment) the best way to do what people want,
> assuming they want
> the right lables on both the original variable and the new
> variable, seems to me to be
> -numlabel label, remove- -vreverse varname,
> generate(newvar)- -numlabel
> label, add- -numlabel newlabel, add-
>
> E.g.
>
> . sysuse auto, clear
> (1978 Automobile Data)
>
> . numlabel origin, add
>
> . 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
>
> . tab foreign, nola
>
>    Car type |      Freq.     Percent        Cum.
> ------------+-----------------------------------
>           0 |         52       70.27       70.27
>           1 |         22       29.73      100.00
> ------------+-----------------------------------
>       Total |         74      100.00
>
> . vreverse foreign, generate(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
>
> . tab Foreign, nola
>
>    Car type |      Freq.     Percent        Cum.
> ------------+-----------------------------------
>           0 |         22       29.73       29.73
>           1 |         52       70.27      100.00
> ------------+-----------------------------------
>       Total |         74      100.00
>
> . d
>
> Contains data from C:\STATA8\ado\base/a/auto.dta
>   obs:            74                          1978 Automobile Data
>  vars:            13                          3 Oct 2002 13:53
>  size:         3,552 (99.9% of memory free)
> ------------------------------------------------------------
> ----------------
> ---
>               storage  display     value
> variable name   type   format      label      variable label
> ------------------------------------------------------------
> ----------------
> ---
> make            str18  %-18s                  Make and Model
> price           int    %8.0gc                 Price
> mpg             int    %8.0g                  Mileage (mpg)
> rep78           int    %8.0g                  Repair Record 1978
> headroom        float  %6.1f                  Headroom (in.)
> trunk           int    %8.0g                  Trunk space (cu. ft.)
> weight          int    %8.0gc                 Weight (lbs.)
> length          int    %8.0g                  Length (in.)
> turn            int    %8.0g                  Turn Circle (ft.)
> displacement    int    %8.0g                  Displacement (cu. in.)
> gear_ratio      float  %6.2f                  Gear Ratio
> foreign         byte   %11.0g      origin     Car type
> Foreign         byte   %11.0g      Foreign    Car type
> ------------------------------------------------------------
> ----------------
> ---
> Sorted by:  foreign
>      Note:  dataset has changed since last saved
>
> . numlabel  Foreign, remove
> (no value label to be modified)
>
> . numlabel  Foreign, remove force
> (no value label to be modified)
>
> . numlabel  Foreign, add
>
> . tab Foreign
>
>       Car type |      Freq.     Percent        Cum.
> ---------------+-----------------------------------
>  0. 1. Foreign |         22       29.73       29.73
> 1. 0. Domestic |         52       70.27      100.00
> ---------------+-----------------------------------
>          Total |         74      100.00
>

Renzo is of course quite right. -vreverse- (user-written) knows
nothing about what you may have done previously with -numlabel-
(official Stata).

However, although Renzo's implication here is that this is
always a nuisance, I can easily imagine situations in which
the two commands together give exactly what you want, i.e.
you want tables etc. to be in order resembling

5. Excellent
...
1. Very poor

I'll look into an adding an option or options to -vreverse-
for fixing this problem -- when it is a problem -- without
modifying the original variable's value labels.

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

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index