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

st: Re: RE: merging variable labels


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: RE: merging variable labels
Date   Mon, 29 Mar 2004 10:03:29 -0500

You can do this within Stata -- Here's a program:

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'
end

*note:  the -file write- command may wrap, depending on email issues

Then you can just

varlabmake varname varlabel, saving(varlabels.do)

to create your do file.  It doesn't have much data checking (does the
varname variable contain valid varnames? etc..) but it should work.

Michael Blasnik
michael.blasnik@verizon.net



----- Original Message ----- 
From: "David Airey" <david.airey@vanderbilt.edu>
To: <statalist@hsphsun2.harvard.edu>
Sent: Saturday, March 27, 2004 11:48 AM
Subject: st: RE: merging variable labels


> I'll do that. Thanks, Nick!
>
> -Dave
>
>
> > The easiest way, I guess, is to copy the
> > second file to make a do file. Each line
> > should then be prefixed with
> >
> > label var
> >
> > and each explanation should be bracketed
> > within " ". With a decent text editor it
> > should be fairly straightforward.
> >
> > Nick
> > n.j.cox@durham.ac.uk
> >
> > David Airey
> >
> > > I was sent two files, one containing data that could be
> > > imported using
> > > insheet, with variable names in the first row, and the other
> > > containing
> > > variable names and a short explanation of each variable. Is there an
> > > easy way to label the variables with the explanations without typing
> > > them in by hand using the label variable command?


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