You need to enclose the macro `name' in double quotes:
local code = substr(`name', -3, .)
needs to be :
local code = substr("`name'", -3, .)
Michael Blasnik
[email protected]
----- Original Message -----
From: "Radu Ban" <[email protected]>
To: <[email protected]>
Sent: Thursday, February 27, 2003 12:21 PM
Subject: st: question about labelling
> Dear all,
>
> I have a lot of variables of the type
>
> xyz101 xyz105 xyz211...
>
> and I want to label them like this:
>
> label var xyz101 "[description] 101"
>
>
> I would like to know whether I can speed up this labelling process, since
> I have over a hundred of these variables.
> I tried the following piece of code:
>
> foreach `name' of varlist xyz* {
> local code = substr(`name', -3, .)
> label var `name' `"indigineous input # `code'"'
> }
>
> but it gives me a type mismatch, which makes me believe -substr- is trying
> to extract the string out of the variable itself not its name. Can anyone
> point the way oout?
>
> Thanks in advance,
>
> Radu Ban
>
*
* 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/