0
votes

I'm currently using Stata 13.1 to examine a long list of float variables (e.g., A1 - A60). Each of these variables represents the frequency of a different medical symptom (e.g., "Insomnia", "Anxiety", "Nausea"). I'd to add labels to each variable to make data analysis a bit easier, but would prefer something more elegant than:

label var A1 "Insomnia"
label var A2 "Anxiety"
.
.
.
label var A60 "Nausea"

Any suggestions are very much appreciated!

1

1 Answers

1
votes

Initially, you need to store the labels in some place. You can use a local macro for that. Below an example with variables that follow some naming pattern (like your example does).

clear 
set more off

*----- example data -----

gen A1 = .
gen A2 = .
gen A3 = .

*----- what you want -----

local mylabels "Insomnia Anxiety Nausea"
local n: word count `mylabels'

forvalues i = 1/`n' {
    label variable A`i' `:word `i' of `mylabels''
}

describe

The looping over parallel lists technique is from: http://www.stata.com/support/faqs/programming/looping-over-parallel-lists/.

See also help macro and help help extended_fcn.