Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Labelling variable based on existing label of another variable

    Hello,

    I was wondering if there is a command that enables you to label a variable based on an existing variable label
    e.g.
    I have a variable X and I use the command:

    label variable x "apples"

    Now I want to run a loop generating variables from x, but I want to include in that loop to label them as "apples" or whatever the existing label for variable x is.

    TIA!

    Cheers,
    Jess

  • #2
    Code:
    sysuse auto
    forval i=2/4{
        gen foreign`i'= foreign
        lab var foreign`i' "`: var lab foreign'"
    }
    desc foreign*
    Res.:

    Code:
    . desc foreign*
    
                  storage   display    value
    variable name   type    format     label      variable label
    ------------------------------------------------------------------------------------------------------------
    foreign         byte    %8.0g      origin     Car type
    foreign2        float   %9.0g                 Car type
    foreign3        float   %9.0g                 Car type
    foreign4        float   %9.0g                 Car type

    Comment


    • #3
      You can do this but how best to do it depends on how you want to generate the variables. For example, with separate a variable label is created automatically. The same is true of tabulate, generate().

      So, more explanation of what you intend seems needed for a better answer than this.

      Comment

      Working...
      X