Announcement

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

  • -capture- doesn't work in Stata 17.0

    Dear All,

    according to Stata's manual: "capture executes command, suppressing all its output (including error messages, if any)..."

    But I can't get it why the -capture- command doesn't work in Stata 17.0. By "doesn't work" here I mean "doesn't suppress the error message in the output".

    Here is what I type:

    Code:
    .
    
    local foo
    capture local foo `"`: dir "./bar" dirs "*"'"'
    directory ./bar not found
    I don't seem to find a way to prevent the error message from appearing.

    My expectation is to have a blank result in foo after running these lines (note I specifically clear the local foo before running this line).

    How can the error message be really suppressed?

    Stata version is 17.0(170130) on Windows, if that matters.

    Thank you, Sergiy

  • #2
    FWIW, same thing happens in version 18.

    Comment


    • #3
      Something strange is happening here and I can't explain it. I am guessing it's to do with Stata first trying to expand the extended function inside of the compound quotes, before it gets assigned to the local macro -foo-. Here's what I find without the wrapping compound quotes:

      Code:
      local foo : dir "./bar" dirs "*"  // gives error message
      directory ./bar not found
      
      capture local foo : dir "./bar" dirs "*"  // capture supresses the error message
      Last edited by Leonardo Guizzetti; 30 May 2023, 16:56. Reason: edit: typo in code comment

      Comment


      • #4
        Dear Leonardo Guizzetti ,

        thank you very much for the helpful and illustrative hint!
        I can totally reduce some quotes in my expressions to use your workaround.

        Clyde Schechter , thank you very much for checking in 18 and congratulations on an upgrade!

        Best, Sergiy

        Comment

        Working...
        X