-------------------------------------------------------------------------------
help for labvalch
-------------------------------------------------------------------------------

Copy and/or delete value labels

labvalch valuelabelname , [ { from(numlist) to(numlist) | swap(#1 #2) } delete(numlist) list ]

Description

labvalch copies and/or deletes specified value labels from value label valuelabelname.

Any label define whatever , modify command that executes changes is echoed to the monitor.

Remarks

Suppose that variable gender is coded 1 for male and 2 for female by

. label def gender 1 "male" 2 "female" . label val gender gender

but we find it convenient to change to 0 and 1:

. replace gender = gender - 1

We need also to change the value labels. Slow but sure is

. label def gender 0 "male" 1 "female", modify

It would normally be best to clean up by also deleting the label for 2:

. label def gender 0 "male" 1 "female" 2 "", modify

An alternative is

. labvalch gender, f(1 2) t(0 1)

Again, it would normally be best to clean up by also deleting the label for 2:

. labvalch gender, f(1 2) t(0 1) delete(2)

Suppose we have a set of labels

. label def rating 1 "poor" 2 "fair" 3 "OK" 4 "good" 5 "excellent"

and we wish to reverse the labelling. This is done by

. labvalch rating, f(1/5) t(5/1)

Options

from(numlist) specifies a numlist of integers whose value labels are to be copied. These labels will not be changed unless an element of the numlist also appears in to( ), or unless they are deleted by delete(). Specifying an integer for which a label does not exist is treated as an error.

to(numlist) specifies a numlist of integers whose value labels are to be defined. Existing value labels are modified.

All replacements take place independently. Thus from(2 1) to(1 2) would swap value labels associated with 1 and 2: the label of 2 becomes that of 1, and vice versa. (swap(1 2) would be another way to do this.)

from() and to() must contain the same number of elements after expansion. This syntax may not be combined with swap().

swap(#1 #2) specifies two integers possessing value labels whose labels are to be swapped. This syntax may not be combined with from() to().

delete(numlist) specifies a numlist of integers whose value labels are to be deleted. Note that all deletions take place after copying. Specifying an integer for which a label does not exist is not treated as an error, but this will be noted.

list invokes label list valuelabelname after the changes produced.

Examples

. labvalch rating, f(1/5) t(5/1)

. labvalch foo, f(1 1 1 1) t(2/5)

. foreach label in a b c d e { . labvalch `label', f(1 2) t(0 1) delete(2) . }

Author

Nicholas J. Cox, University of Durham, U.K. n.j.cox@durham.ac.uk

Acknowledgements

Fred Wolfe made interesting and helpful comments on labcopy and labdel, precursors of this command.

Also see

Manual: [U] 15.6, [R] label, [R] recode On-line: help for label; numlist; recode; labedit (if installed)