Announcement

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

  • Grabbing Multiple Variable Labels

    Suppose I want to get the names of the list of covariates included in a model to display it to users.
    Code:
    sysuse auto, clear
    cls
    foreach x of var foreign price {
    local x : variable label `x'
    di "`x'"
    }
    This displays them separately, but what I want is to iteratively combine each variable label such that they're alongside each other like "Car Origin", "Price". How might I go about this?

  • #2
    Code:
    sysuse auto, clear
    cls
    local wanted
    foreach x of var foreign price {
        if `"`wanted'"' != "" {
            local wanted `wanted',
        }
        local wanted `wanted' `:var label `x''
    }
    display `"`wanted'"'
    This approach of putting -local wanted `wanted' whatever- inside a loop is a very useful idiom for building lists iteratively in Stata.

    Comment


    • #3
      Okay thanks so much!! Clyde Schechter

      Comment

      Working...
      X