Announcement

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

  • option "" incorrectly specified

    Hello, I am having trouble with my Stata program and I do not know what I did wrong...

    The source code is below:
    Code:
    program define myProg, eclass
        version 14.0
        syntax varlist(min=2) [if] [in], [,routine(str)]
        if (`routine' == "FirstRoutine") {
            di "call the first routine"
        } else if (`routine' == "SecondRoutine") {
            di "call the second routine"
        } else {
            di "no such routine available"
        }
    end
    As you can see here, I am simply trying to parse in the correct options. However, after I loaded the auto.dta data, I typed
    Code:
    myProg make mpg, routine = "FirstRoutine"
    in the Stata console and got back an error message saying "option routine incorrectly specified". What seems to be the issue here? Any help is appreciated

  • #2
    The program needs some fixes, minimally


    Code:
    program define myProg, eclass
        version 14.0
        syntax varlist(min=2) [if] [in] [,routine(str)]
        if "`routine'" == "FirstRoutine" {
            di "call the first routine"
        }
        else if "`routine'" == "SecondRoutine" {
            di "call the second routine"
        }
        else {
            di "no such routine available"
        }
    end
    As for

    Code:
     myProg make mpg, routine = "FirstRoutine"
    when did you ever call a Stata option like that? You're thinking of some other language.

    Code:
    myProg make mpg, routine(FirstRoutine)

    (The logic of the first program is strange, but no doubt it's just made up.)

    Comment


    • #3
      The following version functions as you hoped. Note several changes throughout.
      Code:
      program define myProg, eclass
          version 14.0
          syntax varlist(min=2) [if] [in], [,routine(str)]
          if ("`routine'" == "FirstRoutine") {
              di "call the first routine"
              }
          else if ("`routine'" == "SecondRoutine") {
              di "call the second routine"
              }
          else {
              di "no such routine available"
              }
      end
      sysuse auto, clear
      myProg make mpg, routine("FirstRoutine")

      Comment


      • #4
        Thank you for the help!

        Comment

        Working...
        X