help txtlabdef

Title

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

Syntax

txtlabdef [dofile] using filename
[, options]

where dofile is the do-file to be created

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

Use double quotes if dofile or filename contain embedded
spaces. If filename is specified without extension .txt
is the default.

quotes do not remove double quotes from value labels

remove(str) remove str from content in filename

start(#) value labels in filename start at line #

stop(#) value labels in filename end at line #

replace replace existing do-file

append append existing do-file

nodefine create do-file but do not define value labels

Description

txtlabdef defines value labels from a plain text (ASCII) file. The
first line of a value label in the text file must be a valid value label
name. Each line following must start with one integer number followed by
text. The next line that does not start with an integer number marks the
beginning of a new value label. Optionally a do-file is created. Existing
value labels will be modified.

Remarks: integer numbers may be separated from text by ":",
"=", "-", ".", ",", space (" ") or horizontal tab
stop in the (plain) text file. These separators may be mixed between value
labels and even within one value label. There is no need for double quotes,
since everything following the integer number on the same line in the ASCII
file is interpreted as text. In fact all double quotes are removed from the
content in filename.

Options

Options

quotes specifies that double quotes are not to be removed from content
in filename. If text in value labels contains double quotes, use
quotes to make sure they are not removed. Default is to remove all
double quotes.

remove(str) removes str from content in filename. str
is ["]string["] [["][string]["]][...].

start(#) specifies that value labels in the ASCII (plain text) file
start at line #. Lines 1 to # in filename are ignored.

stop(#) specifies that value labels in the ASCII (plain text) file
end at line #. Lines in filename following # are ignored.

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

append specifies that an existing do-file is appended. May only be
specified if dofile is also specified.

nodefine does not define value labels, but only "translates" the ASCII
file and creates a do-file. May only be specified if dofile is also
specified.

Examples

Define value labels form the ASCII file example.txt.

. type example.txt ,asis
yesno

0 no
"1 yes"
2

agree
1: strongly disagre
2: disagree
3: undecided
4: agree
5: strongly agree

fre

1. once a year
2:once a week
3 - once a day

. txtlabdef mydo using c:/ado/example.txt
file mydo.do saved

. label list
fre:
1 once a year
2 once a week
3 once a day
agree:
1 strongly disagree
2 disagree
3 undecided
4 agree
5 strongly agree
yesno:
0 no
1 yes
2

. type mydo.do ,asis
/*value labels from c:/ado/example.txt
created 15 Jan 2011 16:47:44*/

label define yesno 0 "no" ,modify
label define yesno 1 "yes" ,modify
label define yesno 2 "" ,modify

label define agree 1 "strongly disagree" ,modify
label define agree 2 "disagree" ,modify
label define agree 3 "undecided" ,modify
label define agree 4 "agree" ,modify
label define agree 5 "strongly agree" ,modify

label define fre 1 "once a year" ,modify
label define fre 2 "once a week" ,modify
label define fre 3 "once a day" ,modify

Example 2. The ASCII file example2.txt contains some text and
value labels.

. type example2.txt ,asis
This file demonstrates how txtlabdef handles information in a text file.

This is the third line and it contains number 1.
The integer value 1 in the line above is ignored because the line does
not start with an integer number.
Since the following line starts with the integer number
2, txtlabdef will interpret "Since" in line 6 (above)
as a value label name and everything following number 2 in line 7,
will be interpreted as text associated with number 2.

Now we will define a value label, starting with a value label name.
labelname
1 strongly agree
2 agree
3 undecided
4 disagree
5 strongly disagree

Note that txtlabdef will create the value label "labelname". In fact, if
all lines in the ASCII file start with valid (value label) names or an
integer number, txtlabdef will find the value labels in the plain text and
will not terminate.

The problem in this very text file is, that the value label "Since" will
also be created. To prevent txtlabdef from doing so, specifiy

. txtlabdef using example2.txt ,start(12) stop(17)

That's the end of example2.txt.

. txtlabdef using example2.txt

. label list
labelname:
1 strongly agree
2 agree
3 undecided
4 disagree
5 strongly disagree
Since:
2 txtlabdef will interpret Since in line 6 (above)

. clear

. txtlabdef using example2.txt ,start(12) stop(17)

. label list
labelname:
1 strongly agree
2 agree
3 undecided
4 disagree
5 strongly disagree

Saved results

txtlabdef saves the following in r():

Macros

r(labelnames) value label names

Acknowledgments

The name txtlabdef is in line with varlabdef by Roger Newson.

Author

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

Also see

Online: label, file

if installed: varlabdef