-------------------------------------------------------------------------------
help for labgen and labreplace
-------------------------------------------------------------------------------

Generate or replace variables with definitions copied to variable labels

labgen [typname] varname = exp [if exp] [in range]

labreplace varname = exp [if exp] [in range] [, nopromote ]

Description

labgen generates a new variable using generate, except that the definition of the variable, i.e. whatever follows the equals sign, including any if or in qualifiers specified, becomes the variable label.

labreplace replaces an existing variable using replace, except that the definition of the variable, i.e. whatever follows the equals sign, including any if or in qualifiers specified, becomes the variable label.

Thus labgen logy = ln(y) creates a new variable logy with variable label ln(y). Similarly labreplace logy = ln(y) if foo > 2 replaces variable lny with a new variable label ln(y) if foo > 2.

Remarks

A first version of labgen was posted by Paul Lin to Statalist on 16 July 1996. NJC posted a revision on 18 July 1996. Alan H. Feiveson drew my attention to it once more in Statalist postings on 25 September 2008. labgen as published on SSC is revised and labreplace is new as of 13 October 2008.

Note that the :lblname syntax of generate is not supported.

Exceptionally, if the definition exceeds 80 characters in length, then the definition is inserted in notes for the variable and the variable label is a pointer to that effect.

For other commands in similar spirit, search genl and see Weesie (1997), or search defv and see Gleason (1997, 1999).

Examples

. labgen lny = ln(y) . labreplace lny = ln(y) if bar > 2

Author

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

References

Gleason, J.R. 1997. Defining variables and recording their definitions. Stata Technical Bulletin 40: 9-10. (STB Reprints 7: 48-49) http://www.stata.com/products/stb/journals/stb40.pdf

Gleason, J.R. 1999. Update to defv. Stata Technical Bulletin 51: 2. (STB Reprints 9: 14-15) http://www.stata.com/products/stb/journals/stb51.pdf

Weesie, J. 1997. Automatic recording of definitions. Stata Technical Bulletin 35: 6-7. (STB Reprints 6: 18-20) http://www.stata.com/products/stb/journals/stb35.pdf