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

st: Re: Re: ST: transferring labels

From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: Re: ST: transferring labels
Date   Fri, 12 Nov 2004 08:22:14 -0500

I have an ado that I use for this since I often work with database files that contain fields with long versions of variable names that act well as labels. It requires that you have a datafile that contains the variable names and their labels (insheet from excel in your example?). You then type:

varlabmake varname varlab, saving(varlabel_set1)

program define varlabmake
version 8.2
syntax varlist (max=2), saving(str)
if substr("`saving'",-3,.)!=".do" local saving "`saving'.do"
tempname f
tokenize `varlist'
file open `f' using "`saving'", write text replace
local N=_N
forvalues i=1/`N' {
local var=`1'[`i']
local lab=`2'[`i']
if "`var'"!="" & "`lab'"!="" {
file write `f' "label var `var' " _char(34) "`lab'" _char(34) _n
file close `f'

Michael Blasnik
[email protected]

----- Original Message ----- From: "Eric Uslaner" <[email protected]>
To: <[email protected]>
Sent: Thursday, November 11, 2004 6:13 PM
Subject: st: Re: ST: transferring labels


I have downloaded a data set that is in 3 parts, all in Excel.  Files 2
and 3 are data, file 1 is a list of variable names and labels. I have
transferred the data with names to Stata, but the labels are perplexing.
Here is  the format of the Excel spreadsheet with the variable names
and labels:

Column A    Column B       Column C    Column D   Column E
varname     varlabel          divider        varname     varlabel
etc.               etc.                                    etc.

Columns A&B are for data set 2 and C & D for data set 3 (though this is
no problem--I can copy them into one column since the cases are

Is there a way to transfer the variable labels without doing a lot of
typing.  Stata Technical Support suggested putting each variable label
into a do-file with quotation marks around each label (which I would
have to type in by hand) and then pasting:

label var varname "varlabel" for each variable.

Does anyone have a more expeditous (and less tedious) way of doing this


Ric Uslaner
[email protected]

*   For searches and help try:

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