Your description does not make it clear precisely
how your extra file is organised, but from the
information you provide the problem resembles
that posed by David Airey on 27 March.
> 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?
I suggested
> 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.
and Michael Blasnik suggested
> 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's program assumes that you have already read into Stata your
names, as one variable, and your labels as another variable. That
will in most cases depend on some prior editing by you.