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

RE: st: labelling issue


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: labelling issue
Date   Fri, 12 Sep 2003 11:26:04 +0100

Eric Uslaner
>  
> I have an Excel spreadsheet (someone else created it) with 
> three worksheets.  Two have data sets that I have 
> transferred by cutting and pasting into Stata and merging.  
> The third has four columns:  
>  
> Column 1:  variable name data set 1
> Column 2: variable label data set 1
> Column 3: variable name data set 2
> Column 4: variable label data set 2
>  
> Is there a way to link the variable names and labels (by 
> cutting and pasting?) into the merged data set without 
> having to retype each of the labels?  I presume that you 
> can't do all of this at once, if at all, but column by 
> column would be great.

I think you need to import the names and 
labels into the data set to which they apply. 
  
Let's suppose your variables to be renamed 
are in <varlist> and their proper names are in -ericsnames-
and their proper variable labels are in -ericslabels-: 

local i = 1 
foreach v of var <varlist> { 
	label var `v' `"`= ericslabels[`i']'"' 
	rename `v' `= ericsnames[`i++']' 
} 

I'm assuming that the left-to-right order of 
variables maps onto the top-to-bottom order of names
and labels. 

Some of the associated jiggery-pokery is discussed in 
Stata Journal 3(2), 185-202 (2003). 

Nick 
[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