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

Re: st: labels as values of a string variable


From   James Cui <[email protected]>
To   [email protected]
Subject   Re: st: labels as values of a string variable
Date   Fri, 03 Jun 2005 09:57:23 +1000

I think if you put the double quote around label1, it should be OK. Try for example

egen id = group(string)
local i=1
while `i'<=2 {
preserve
keep if id==`i'
local label`i' = string[_n]
label variable id `"`label`i''"'
tab id
local i=`i'+1
restore
}

for data
+--------------+
| string |
|--------------|
1. | ad "c c" d |
2. | ced "adb" ed |
+--------------+

Then you have

ad "c c" d | Freq. Percent Cum.
------------+-----------------------------------
1 | 1 100.00 100.00
------------+-----------------------------------
Total | 1 100.00
(1 observation deleted)

ced "adb" |
ed | Freq. Percent Cum.
------------+-----------------------------------
2 | 1 100.00 100.00
------------+-----------------------------------
Total | 1 100.00


Cheers
James.


R.E. De Hoyos wrote:

James,

Thanks for your suggestion. Unfortunately it didn't work. The value that I am trying to assign is a string containing space, e.g. "Gross foreign direct investment (% of GDP)". Therefore I have to include the quotation marks (""). In fact the coding I send in my previous email was assigning the string values to the local macros, the problem was when I tried to label the variables using those local macros.

Best,

Rafa

----- Original Message ----- From: "James Cui" <[email protected]>
To: <[email protected]>
Sent: Thursday, June 02, 2005 3:25 PM
Subject: Re: st: labels as values of a string variable



If you change
local label`i' = "string[_n]"
to
local label`i' = string[_n]
it should work.
The latter assigns the value of string[_n] to label`i'.

James.


----- Original Message -----
From: "R.E. De Hoyos" <[email protected]>
Date: Thursday, June 2, 2005 6:54 pm
Subject: st: labels as values of a string variable

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 {
   preserve
   keep if id==`i'
   local label`i' = "string[_n]"
   local i = `i'+1
   restore
}

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,

Rafa

________________________
R.E. De Hoyos
Faculty of Economics
University of Cambridge
CB3 9DE, UK
www.econ.cam.ac.uk/phd/red29
*
*   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/

*
*   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/

*
*   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/

--
James Cui, PhD MMed BSc (Stats)
Senior Research Fellow
Department of Epidemiology & Preventive Medicine
Monash University
Alfred Hospital Campus, 89 Commercial Road
Melbourne, Victoria 3004
Australia
Tel: 990 30570
Fax: 990 30556
Email: [email protected]


*
*   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