*! version 1.1 24 Apr 2018

Title

labeldatasyntax -- Produce syntax to label variables and values, given a data dictionary

Syntax

labeldatasyntax [using filename], saving(filename)
[options]

You may enclose filename in double quotes and must do so if
filename contains blanks or other special characters.

replace specifies that the saving file be replaced if it already exists

Description

labeldatasyntax creates a syntax file to label variables and/or values, given a data dictionary is provided in one of a few specific formats.
The resulting syntax can look like this:

label define regionlbl 1 "North" 2 "East" 3 "South" 4 "West"

label define sexlbl 1 "Male" 2 "Female"

label define yesnolbl 0 "No" 1 "Yes"

label values sex sexlbl

label values region regionlbl

label values badears yesnolbl

label values respprobs yesnolbl

label variable sex "Gender"

label variable region "Where the child lives"

label variable age "Age of child in years"

label variable dob "Date of birth"

label variable badears "Has bad ears?"

label variable respprobs "Has respiratory problems?"

There are two general formats of the data dictionary that can be used with labeldatasyntax.

Format I. When the data dictionary consists of just one file (dataset currently in memory) with variables and their descriptions and/or values and labels.

The file may contain variables called: variable description codeset value label

Format II. When the data dictionary consists of two files.

File (a) (dataset currently in memory) may contain variables called: codeset value label

This file is used to create syntax such as:

label define yesnolbl 0 "No" 1 "Yes"

File (b) (using filename.dta) may contain variables called: variable codeset description

This file is used to create syntax such as:

label values badears yesnolbl

label variable badears "Has bad ears?"

Remarks

i. It is hoped that the .xlsx (and/or .csv) files provided in this package could be useful for users in
communicating to data providers what is a convenient format to receive a data dictionary associated with a dataset.

ii. All variables are optional. You just might not get many lines of syntax.

iii.variable need not be repeated for every row detailing the connection between value and label (though it can be). The same is true for codeset.

iv. codeset is simply a name (I could alternatively have called it: value_label_name or vallabname or lblname)
corresponding to a set of codings for categorical variables.

v. If the dataset currently in memory does not have a variable called codeset, then codeset will be generated (. generate codeset = variable)

vi. The presence or absence of blank lines in a .dta file makes no difference to anything.

Examples

(The examples assume the ancillary files have been downloaded to the current folder.)

Example 0

. import excel "Guide. How to share data from a project in Excel v2.xlsx", sheet("Data Dictionary1") cellrange(A2:D27) firstrow clear

. labeldatasyntax, saving("ex0_label.do")

. import excel "Guide. How to share data from a project in Excel v2.xlsx", sheet("Data1") cellrange(B2:K8) firstrow clear

. describe

. do "ex0_label.do"

. describe

. browse

Example 1

. import delimited "ex1_datadictionary.csv", varnames(1)

. browse

. labeldatasyntax, saving("ex1_label.do")

. doedit "ex1_label.do"

Example 2

. import delimited "ex2_datadictionary.csv", varnames(1)

. browse

. labeldatasyntax, saving("ex2_label.do")

. doedit "ex2_label.do"

Example 3

. import delimited "ex3_allvariables_b.csv", varnames(1)

. browse

. save "ex3_allvariables_b.dta"

. import delimited "ex3_codesetinfo_a.csv", varnames(1) clear

. browse

. labeldatasyntax using "ex3_allvariables_b.dta", saving("ex3_label.do")

. doedit "ex3_label.do"

Author

Mark Chatfield

University of Queensland

Australia

M.Chatfield@uq.edu.au