Announcement

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

  • Can I use symbols in a "label variable" label? Having trouble is $, _ {

    I use this line of stata code:

    label variable xvar "XVAR$_{t}$"

    When I output regression results using outreg2, the above variable shows up as XVAR$. I read the help file but nothing about using symbols in the labels.
    Thank you
    joanne

  • #2
    Yes, you can use symbols in a variable label. But the $ symbol has a special meaning to Stata: it introduces a global macro. So with what you gave Stata, it is substituting the contents of the global macro _{t}$, which, I'm guessing you have never created, and is therefore taken to be an empty string. To specify that you want a literal dollar sign, you need to "escape" it with a backslash character. Thus:

    Code:
    label var x "XVAR\$_{t}\$"
    will get you what you want.

    Comment


    • #3
      Thank you!

      Comment


      • #4
        The solution described above will works only in some cases. I would like to label variable x "$D_{2010}$" and use the label for outreg2. Applying the proposed solution and using outreg2 , the variable x will show up as {2010}$. However, the label of variable x shows up correctly in stata as $D_{2010}$.
        Any help is very much appreciated.

        Comment


        • #5
          Clearly my solution gets you the desired label within Stata, but then outreg2 somehow mangles it. (I suspect that outreg2 somewhere along the line further interprets the $ as the start of a global macro, but I don't really know.) Perhaps somebody who really knows outreg2 can help out. I don't use that command and really am out of my depth at this point.

          Comment


          • #6
            Unfortunately, this is the same story, not another. The price of using $ to indicate global macro names is that each time Stata evaluates (e.g. displays) something, it tries to interpret anything following $ as a global macro name and substitutes the contents of that global macro at that place. That includes substituting an empty string if the macro doesn't exist, as it's quite legal to refer to a macro that doesn't exist; a non-existent macro and an empty string are equivalent.

            You can protect a dollar sign against that interpretation by using the backslash as an escape character, so the backslash is stripped and the dollar sign is inserted safely, as Clyde pointed out.

            So far, so good.

            However, precisely nothing has immunised that dollar sign against the same interpretation the next time it is encountered. Getting out what you put in is as perilous as the reverse.

            I've not looked inside outreg2 (from SSC, as you are asked to explain), but I am confident this is what is happening: when the program evaluates that string, which could just be when it displays it next, the same rule applies.

            This is undoubtedly a real pain, as many people have genuine need to use dollar signs in their usual non-Stata sense. In some cases, more backslashes help, one to be stripped each time, but you have to count backslashes correctly; in some cases using char(36) to indicate a dollar sign is a work-around, provided that it is passed through display at the end; if I had to work with dollar signs a lot I would just use some string such as "USD" and then edit as appropriate in my final document or graphs.

            whatsoever: Changing your identifier to a full real name, as requested on this forum, would be very much appreciated.

            Comment


            • #7
              Dear Clyde and Nick. Thank your very much for you quick replies. It is not the currency I am interested in, but the $ sign for latex, where a formula starts and ends with $. I will try the workarounds suggested. Thanks again.
              If it is appreciated I would to change my username, however, is there still no option to do it myself? Thanks again
              How can I change my username? The question may sound silly, but I really cannot find how to do that?

              Comment


              • #8
                LaTeX uses: same applies. Any string that doesn't occur otherwise could be edited in one shot in a text editor.

                Home page: "For lots more information, see the Statalist FAQ."
                http://www.statalist.org/forums/help Section 6.
                "Contact Us" in bottom right-hand corner of every Statalist page.

                Comment


                • #9
                  I have a very similar question. I have a combined treatment (it is currently labelled A&B) - now I use outreg2 with the label command to show this value label (among others) but my tex taels become a mess, as LaTeX assumes it to be in another field in the table (& happens to be the thing that makes new columns in LaTeX).

                  Is there any work-around I could use?

                  Comment

                  Working...
                  X