help labren
-------------------------------------------------------------------------------

Title

labren -- Rename value labels

Syntax

Change single value label name

labren oldlblname newlblname

Change groups of value label names

labren (oldlblname-list) (newlblname-list) [, options]

Predefined changes

labren [oldlblname-list] , transformation-options [dryrun]

options Description ------------------------------------------------------------------------- options csis(spec) create lblname-lists. See Remarks dryrun display oldlblname to newlblname mappings. Do not change any value label names

transformation-options upper change value label names to uppercased characters lower change value label names to lowercased characters prefix(stub) prefix value label names with stub suffix(stub) suffix value label names with stub subst(this that) in value label names change this to that before(before) remove before and any text following after(after) remove after and any text preceding noexclude do not remove before or after strfcn(strfcn(args)) apply string function strfcn(args) to value label names symbol(char) use char as placeholder in args -------------------------------------------------------------------------

Description

labren changes value label names. New value labels are attached to variables currently using old value labels. Old value labels are dropped from memory.

If more than one transformation option is specified, labren applies options in the following order.

1. before or after select text 2. all occurrences of this are changed to that 3. value labels are changed to upper- or lowercased characters 4. string function strfcn(args) is applied 5. prefix and/or suffix is added

Options

+---------+ ----+ Options +----------------------------------------------------------

csis(spec) uses cyclic substitution in strings to create lblname-lists. The synonym x() may be used. See Remarks.

dryrun displays oldlblname to newlblname mappings and does not change any value label names. This option is especially useful with csis().

+------------------------+ ----+ Transformation options +-------------------------------------------

upper changes value label names to uppercased characters. May not be specified with lower.

lower changes value label names to lowercased characters. May not be specified with upper.

prefix(stub) prefixes value label names with stub. May be combined with suffix().

suffix(stub) suffixes value label names with stub. May be combined with prefix().

subst(this that) substitutes all occurrences of this in value label names with that. Value label names in which this is not found are left unchanged. Specifying that as ("") removes this from value label names.

before(before) removes before and any text following from value label names. Thus, value label names will be changed to contain any text preceding before. Value label names in which before is not found are left unchanged. May not be specified with after.

after(after) removes after and any text preceding from value label names. Thus, value label names will be changed to contain any text following after. Value label names in which after is not found are left unchanged. May not be specified with before.

noexclude prevents labren from removing before or after from value label names. Specifying before(g) noexclude will change value label name origin to orig. Specifying before(g) will change value label name origin to ori.

strfcn(strfcn(args)) applies any string function to value label names. In args use placeholder @ to refer to value label names. The general from of this option is strfcn(strfcn("@" [, args])).

symbol(char) uses char as placeholder for value labels in args. Default placeholder is @. May only be specified with strfcn.

Remarks

In csis(spec)

spec is

symbol list [\ symbol list ... ]

symbol is one character (e.g. @, #, ...) and list is a (num)list.

In

. labren (oldlbl1 oldlbl2) (@new) ,csis(@ a b) @new will be changed to anew bnew. Thus, oldlbl1 will be renamed anew and oldlbl2 will be renamed bnew.

More than one symbol may be used. The above line can be rewritten as

. labren (oldlbl#) (@new) ,csis(@ a b \ # 1/2)

You may also use more than one symbol within one name. The line

. labren (oldlbl1 oldlbl2 oldlbl3 oldlbl4) (@new#) ,csis(@ a b \ # 1/2)

will rename oldlbl1 anew1, oldlbl2 anew2, oldlbl3 bnew1 and oldlbl4 bnew2. Note the difference between

[...] (@new#) ,csis(@ a b \ # 1/2)

and

[...] (@new#) ,csis(# 1/2 \ @ a b)

where the former will change @new# to anew1 anew2 bnew1 bnew2, and the latter will change it to anew1 bnew1 anew2 bnew2

There is one special case in which option csis is not needed. In

. labren (old1 old2 old3) (new#) new# will be changed to new1 new2 new3. Here # must be used as symbol and it may only be used in newlblname. The numbers will always start at 1. There will be as many numbers as there are old names.

Wildcards (*, ?, ~) are treated as any other character when used as symbol. If you want to abbreviate a list of existing value labels, see labunab (if installed).

Example

. sysuse nlsw88

Change racelbl to newlbl . labren racelbl newlbl

Remove lbl from all value label names . labren ,before(lbl)

Rename value labels occ and ind to new1 and new2 . labren (occ ind) (new#)

Rename new, new1 and new2 Anew, Bnew and Cnew . labren (new new#)(@new) ,csis(# 1 2 \ @ A B C)

Acknowledgments

The program, and especially support for multilingual datasets, is inspired by Jeroen Weesie's labelrename.

Nick Cox originated the transformation_options.

The syntax is inspired by official Stata's rename group (release 12).

Author

Daniel Klein, University of Kassel, klein.daniel.81@gmail.com

Also see

Online: label

if installed: labelrename, labvalclone, labutil2