help labascii
-------------------------------------------------------------------------------

Title

labascii -- Define value labels from ASCII (text) file

Syntax

labascii [dofile-name] using filename [, options]

where dofile-name is the do-file to be created

and filename is the ASCII (text) file, containing the value labels

Use double quotes if dofile-name or filename contain embedded spaces. If filename is specified without extension .txt is the default. For dofile-name it is .do.

Description

labascii defines value labels from a plain text file that contains only ASCII characters. In filename each line, starting with a valid value label name, marks the beginning of a new value label. The lines in between define the integer-to-text mappings. Lines starting with non-integer numbers are skipped. Optionally a do-file, containing the value label definitions, is created.

Options

modify modifies existing value labels (see label define).

parse("pchars") specifies the parsing characters used to determine the first word in each line of filename. Default is parse(" ") (see tokenize).

from(ptrn) specifies pattern in filename that are to be replaced. ptrn is ["]ptrn["] [["][ptrn]["]][...]. Specified ptrns are replaced with ptrns in to(). If to() is not specified, it defaults to to("") (see filefilter).

to(ptrn) specifies pattern to replace from() in filename. ptrn is either ["]ptrn["] (meaning one pattern), or ["][ptrn]["][...], where the number of ptrns equals the number of ptrns in from(). to may only be specified with from(), but it is not required (see filefilter).

skip(numlist) specifies that lines numlist in filename be ignored.

start(#) specifies start of value label definitions in filename. Lines 1 to # in filename are ignored.

stop(#) specifies end of value label definitions in filename. Lines in filename following # are ignored.

replace replaces the do-file if it already exists. May only be specified if a dofile-name is specified.

nodefine creates a do-file containing value label definitions, but does not run it automatically. May only be specified if dofile-name is specified.

Examples

Suppose a log-file, created as

. log using foo ,text . sysuse nlsw88 ,clear . label list . log close

First, we clear all value labels from memory.

. label drop _all

To (re-)define the value labels from foo.log we type

. labascii using foo.log ,parse(": ")

We used option parse(": "), because value label names in foo.log are followed by a colon (:), which makes them invalid value label names. Since no value label in the nlsw88 dataset uses a colon as a valid charcater, we could have also typed

. labascii using foo.log ,from(:)

or, more explicitly

. labascii using foo.log ,from(:) to("")

removing all colons before extracting value labels from foo.log.

Optionally we may want to save the do-file used to define the value labels as bar.do. We do so typing

. labascii bar using foo.log ,parse(": ")

Note: I recommend not removing periods (.), because this leads to problems defining labels for extended missing values (see missing) and the handling of non-integer values. If integer values are directly followed by a period in the ASCII file, you do not need to specify parse().

Whenever you parse on period, specifying parse(". ") is usually better than parse(.).

Saved results

labascii saves the following in r():

Macros r(labelnames) value label names

Author

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

Also see

Online: label, file if installed: varlabdef, labutil2, txtlabdef (old)