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

st: Re: ST: labelling again


From   "Eric Uslaner" <[email protected]>
To   <[email protected]>
Subject   st: Re: ST: labelling again
Date   Sat, 13 Sep 2003 17:11:59 -0400

Yesterday I posted a query that Nick Cox kindly answered:

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

 
However, I am unsure of what I need to do.  I now did a cut a paste from Excel and have a list of variable names and variable labels.  But they are in (an otherwise empty) Stata data set labelled var1 and var2.  Call this data set datasetlabels.   The variables are in a data set called dataset.  How do I merge the two together?
 
Flying blind, I merged the two data sets and typed in, with the result:
 
local i = 1 
 
. foreach v of var <varlist> { 
  2. label var `v' `"`= var2[`i']'"' 
  3. rename `v' `= var1[`i++']' 
  4. } 
< invalid name
 
There is clearly something I am not understanding at a fundamental level.  And I think it has to do with how to put the original data set together with the "data set" containing just the labels and the variable names (since the two data sets have different numbers of observations).  Thanks in advance for any help.
 
Ric Uslaner
 




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