Announcement

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

  • Options starting with "no" doesn't work, bug or feature?

    I am defining a program that has non-required options. When the option starts with "no", it doesn't work as expected. If I change it to "No" it works but is case-insensitive in the code (i.e., I can call the option by no... further down in the code).

    This is in Stata 16.1, running on Windows.

    Is there some feature of Stata I am missing out on, which is why this is proper behavior?

    See below MWE
    Code:
    cap program drop doesnt_work
    cap program drop works
    cap program drop works_but_weird
    
    program define doesnt_work
        syntax, [no_option]
        
        if "`no_option'" == "" {
            disp "no option was called ..."
        }
        else {
            disp "no-option used!"
        }
    end
    
    program define works
        syntax, [n_option]
        
        if "`n_option'" == "" {
            disp "no option was called ..."
        }
        else {
            disp "no-option used!"
        }
    end
    
    program define works_but_weird
        syntax, [No_option]
        
        if "`no_option'" == "" { // note also, case-insensitive (no v.s. No)
            disp "no option was called ..."
        }
        else {
            disp "no-option used!"
        }
    end
    
    doesnt_work            // prints "no option was called ..." 
    doesnt_work, no_option // prints "no option was called ..."
    
    works                  // prints "no option was called ..."
    works, n_option        // prints "no-option used!"
    
    works_but_weird        // prints "no option was called ..."
    works_but_weird, no_option // prints "no-option used!"
Working...
X