Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: syntax question - how to put the variable label into a macro


From   Roger Newson <[email protected]>
To   [email protected]
Subject   Re: st: syntax question - how to put the variable label into a macro
Date   Wed, 07 Jul 2004 16:03:43 +0100

At 15:38 07/07/2004, Ginger Smith wrote:
Hello,

I have some data set up in a funny way where the "data" is actually contained in the variable label.

The variables are mt_1_1996 mt_2_1996 mt_3_1996 etc. with an "X" in the column to indicate that the observation goes with the city. The names of the city are in the variable label.
I need to grab the variable label but am having trouble with the syntax.

Here's my code that puts in Akron, OH wherever there is an "X" in any of the variables:

forvalues i = 1(1)89 {;
local tempvar = "Akron, OH" ;
replace mt_`i'_1996= "`tempvar'" if mt_`i'_1996=="X" ;
};

I want to do something like this (the second line is the problem):

forvalues i = 1(1)89 {;
local tempvar = variable label mt_`i'_1996 ;
replace mt_`i'_1996= "`tempvar'" if mt_`i'_1996=="X" ;
};
To get a variable label into a macro, use the -variable label- extended macro function, as in

local xlab: var lab x

where x is a variable. (Note that you use a colon instead of an = sign.) For more about extended macro functions, see -help macro- or -[P] macro-, where -[P]- is the Stata programming manual.

I hope this helps.

Roger




--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]
Website: http://www.kcl-phs.org.uk/rogernewson

Opinions expressed are those of the author, not the institution.

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index