Declan Trott
> > when I create new variables by renaming or
> > transforming old ones, I would like to be able to give the
> > new variables
> > the same variable labels as the old ones without having to
> > type out "label
> > variable varname text" for each new variable.
> >
> > eg I have a collection of information on different houses
> > and the variable
> > "x" is the number of bedrooms. First I want to rename x as
> > something more
> > intuitive:
> >
> > generate bedrooms = x
> >
> > And then I create dummy variables for each value of
> > bedrooms that occurs in
> > the data:
> >
> > tab bedrooms, generate(bedrooms)
> >
> > Is there any way that I can give each of the bedrooms
> > dummies (bedrooms1,
> > bedrooms2 etc) the same variable label as x without having
> > to type the
> > "label . . ." command individually for each one?
> >
>
> You want to do this for a bunch of variables.
> The literal answer to your question is
>
> foreach v of var bedroom? {
> _crcslbl `v' bedroom
> }
>
> or
>
> foreach v of var bedroom? {
> copydesc bedroom `v'
> }
>
> or
>
> local lbl : variable label bedroom
> foreach v of var bedroom? {
> label var `v' `"`lbl'"'
> }
>
Not Declan's question, but there seems a natural
sequel to this. What if you don't want exactly
the same label, but one indicating which
variable you are dealing with? -tabulate, gen()-
does produce such a label, but it is often ugly.
Suppose the maximum number of bedrooms is 9.
local lbl : variable label bedroom
forval i = 1/9 {
label var bedroom`i' "`lbl' is `i'"
}
illustrates one line of attack -- and
also how knowing the low level syntax
is needed for some problems.
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/