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

st: labels as values of a string variable

From   "R.E. De Hoyos" <[email protected]>
To   <[email protected]>
Subject   st: labels as values of a string variable
Date   Thu, 2 Jun 2005 11:54:58 +0300

I want to attach labels to a group of variables (varlist).

The labels that I want to use for each variable are available as observations in one of the variables (string). I tried the following:

levels string, local(labels)
tokenize `lables'

* An error occurred because the string values contained spaces. Therefore I tried:

egen id = group(string) //20 groups
local i=1
while `i'<21 {
keep if id==`i'
local label`i' = "string[_n]"
local i = `i'+1

When I used -di `label1'- the label names where correctly displayed. However when I tried to attached them to the variables using -label var- :

label var var1 "`label1'"

The label attached was "string[_n]" and not the value of it.

Many thanks,


R.E. De Hoyos
Faculty of Economics
University of Cambridge
CB3 9DE, UK *
* For searches and help try:

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