Announcement

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

  • Local variable list macro is giving error

    Hi everyone,

    I am trying to use the local macro to define few variables in a group i.e.

    local A var1 var2 var3
    local B 'A' var4 var5 var6

    However, when I run any command like
    sum 'A'
    or;
    display 'A'

    Stata gives the following error
    . display 'A'
    'A' invalid name
    r(198);

    I have looked at many other posts at Stata forum and I think many have used the macro for this task in similar way. I am not sure why the macro is not working. Is there some package needs to be installed for that to work?

    Secondly, what if we have a long list of variable and we want to define a local group of these variables for descriptive statistics etc. i.e.

    local A var1 var2 var3 \\\
    var4 var5 var6

    I have tried the above that is also not working. Or whether the following would be a good approach.

    local A var1 var2 var3
    local B " 'A' var1 var2 var3 "

    Finally, I have read the delimit possibility. But if we use delimit would it be for whole dofile or can be used for part of dofile. I have tried that as well however to no avail. It worked from dofile but the problem is similar after local command is performed, I am unable to do anything with the list due to same invalid name error. Any help of suggestion would be much appreciated.

    Regards,

  • #2
    It's the quotation marks.

    Code:
    .             local answer 42
    
    . di 'answer'
    'answer' invalid name
    r(198);
    
    . di `answer'
    42
    See 18.3.1 at https://www.stata.com/manuals/u18.pdf


    For the left single quote, we use the grave accent, which occupies a key by itself on most computer keyboards. On U.S. keyboards, the grave accent is located at the top left, next to the numeral 1. On some non-U.S. keyboards, the grave accent is produced by a dead key. For example, pressing the grave accent dead key followed by the letter a would produce a; to get the grave accent by itself, ` you would press the grave accent dead key followed by a space. This accent mark appears in our printed documentation as ‘.

    For the right single quote, we use the standard single quote, or apostrophe. On U.S. keyboards, the single quote is located on the same key as the double quote, on the right side of the keyboard next to the Enter key

    What you use as line delimiter doesn't bite here: that's a separate question.

    Comment


    • #3
      Thank you so much Nick. I really appreciate your help. Now, it works.

      Comment

      Working...
      X