Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: How Can I Store a Variable's Label to Label Another Variable?


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: How Can I Store a Variable's Label to Label Another Variable?
Date   Wed, 24 Oct 2012 10:55:42 +0100

-copydesc- (SSC) is a user-written program; you are asked to explain
where it comes from. (By the way, -copydesc- morphed into -clonevar-,
which is now an official command. -copydesc- is only of real use to
people still using Stata 6 or 7. -clonevar- was added to Stata 8.)

That said, you are correct that -copydesc- is not the answer here, and
the solution to your problem is more direct.

foreach X of varlist   inflation_r  wages_a {
              generate `X'_1 = `X'/2
              local label : variable label `X'
              label variable `X'_1 `"Half of `label''"'
}

See -help extended fcn-.

On Wed, Oct 24, 2012 at 10:46 AM, Charalambos Karagiannakis
<[email protected]> wrote:

> The loop below labels the new variables using the name of the
> original variables (see line 3). Is there any way to label the new variable
> using the label (instead of the name) of the original variable? I found the
> command ‘copydesc’ however that command is used when you want to copy the
> description of another variable exactly as it is. In my case below the label
> of the new variable contains a couple of other words as well.
>
>
>
> local i = 1
>
> foreach X of varlist   inflation_r  wages_a {
>
> generate `X'_1 = `X'/2
>
> label variable `X'_1 `"Half of `X'"'
>
> }
>
>
>
> Since command ‘describe’ gives also the variables’ labels I tried to see
> (using the ‘return’ command) whether it saves any results. However, is seems
> like it does not save the labels. Is there any way to label variable `X'_1
> as: Half of ‘and then here I would like the label of variable X instead of
> the name of variable X’?

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index