Announcement

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

  • for any label variables

    Hi,

    I know that the "for" has been abandoned for years but I am still using it when labelling long lists of variables eg:

    for any x y \ "this is my first var" "this is my second" : label var X "Y"

    To modernize the code I have tried :
    local X x y
    local Y "this is my first var" "this is my second"
    local n : word count `X'
    forvalue i=1/`n' {
    local a : word `i' of `X'
    local b : word `i' of `Y'
    label var `a' `b'
    }
    but my `b' does only include the first word not the label. Is there a way to easily parse the local with the labels?

    Thanks

  • #2
    You want

    Code:
    ...
    local Y `""this is my first var" "this is my second""'
    ...
    label var `a' `"`b'"'

    Comment


    • #3
      By the way, elabel (SSC, SJ, or GitHub) does this

      Code:
      elabel variable (x y) ("this is my first var" "this is my second")

      Comment


      • #4
        thanks

        Comment


        • #5
          Backing up to the original question: It is really hard to improve on

          Code:
          label var x "some stuff"
          label var y "more stuff"
          and, sure, you want to do this for many more variables, but

          1. whatever you do involves specifying the different variable labels

          2. you can reduce the repeat typing by copy and paste in your favourite text editor

          3. from other points of view the ideal for this is likely to be a do-file which is easy for the original programmer or anyone following to understand, easy to modify, and easy to show without too much explanation to yet other people.

          for is not even "undocumented" in Stata's sense but absolutely not documented. (There are still some ancient FAQs arising from the terrible tangles that people got into with for before Stata 7.)

          NB this is Stata's for, abandoned in Stata 7, except in the sense that it still works if you use it correctly. It's nothing at all to with Mata's for.

          Comment

          Working...
          X