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

RE: st: how to extract labels


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: how to extract labels
Date   Wed, 6 Nov 2002 08:48:35 -0000

Ulrich Kohler
> 
> The extended macro function -variable label- is your 
> friend. Something like 
> the following might work:
> 
> gen str1 labelvar = ""                 /* <- generate an 
> empty string var */
> local i 1                              
> foreach var of varlist `outcomes' {
> 	local lab: variable label `var'  /* <- save variable 
> label in local `lab'
>         replace labelvar = "`lab'" in `i'  /* <- store 
> contents of `lab' in */
>         local i 1
> }
> 

A small typo here, I think. I suggest 

gen str1 labelvar = "" 
local i 1                              
foreach var of varlist `outcomes' {
	local lab: variable label `var' 
      replace labelvar = "`lab'" in `i'  
      local i = `i' + 1
}

Also, for generality, this should be 
`"`lab'"' for coping with any embedded 
double quotes. 
 


Nick 
n.j.cox@durham.ac.uk 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index