Announcement

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

  • Multiple commands in one line stored in a local

    I have a problem executing a local with multiple Stata commands separated by ";".

    If I use this code
    Code:
    sysuse auto, clear
    
    #delimit ;
    regress price weight; su price;
    #delimit cr
    the two commands are executed correctly.

    However, if I like to create a local with the commands,
    Code:
    local multiple_commands = "regress price weight; su price"
    
    #delimit ;
    `multiple_commands';
    #delimit cr
    Stata returns
    ; invalid name
    r(198);
    .

    Can someone tell me how to fix this? I tried to use different characters before the delimiter ";" such as `;' or \;, but it did not work.
    "
    Thank you in advance!
    Martin

  • #2
    I would suggest to you that, instead of using locals to smuggle a sequence of commands, rather you can put those command into their own do file and then simply -include- that do file where they are needed. It makes it easier than trying to hack around with changing delimiters, and it's cleaner to read and maintain.

    Comment

    Working...
    X