Announcement

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

  • Embedding double quotes inside a macro argument...

    Hi Everyone,
    I just made a quick example of the issues in my current program. I'm having the hardest time figuring this out. I've tried every combination of double quotes/embedding options. If I double quote in the program call line, the argument (where_1) goes unrecognized. Any suggestions here? This seems so daarrrrn simple...


    cap program drop auto_test
    program define auto_test
    args where_1 where_2
    sysuse auto, clear

    g test_var1 = `"keep if make="AMC Concord""'
    ta test_var1
    g test_var2= `where_1'
    ta test_var2
    `where_1'
    `where_2'
    end

    auto_test `"keep if make="AMC Concord""' "keep if price>=5000"


  • #2
    I see two problems with your code. The first is the line

    Code:
    g test_var2= `where_1'
    which should be

    Code:
    g test_var2= `"`where_1'"'
    as you need to reinstate the delimiters which were stripped when the program read its arguments.

    The second is the line

    Code:
    keep if make="AMC Concord"
    which is just text the first two times you use it, but an illegal command when you try to execute it as you need == not =.

    For debugging, use

    Code:
    macro list
    to get Stata to show you the macros it knows.

    Please change your identifier to a given name and family name, Eric. See the FAQ for how to do this.

    Comment


    • #3
      Thanks Nick Cox, it was the `"`where_1'"' I was really looking for. I definitely tried that variation, but the bug was in the display command (which I generally use to list the macros). Changing my name now.

      Comment

      Working...
      X