Announcement

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

  • ado programming - Switching algorithm based on version

    With Stata 14 having introduced the ustrregex range of functions, I can optimise performance but allow backwards compatibility with [something like] the code below:
    Code:
    if c(stata_version)>=14 {
        //newer regex replace all command
        ustrregexra("`markunits'", " +", ",")
    }
    else {
        while (regexm("`markunits'", " +")){
           local markunits = regexr("`markunits'", " +", ",")
        }
    }
    But I do not have multiple versions of Stata to test this code. My questions therefore are:
    1. I am assuming c(version) relates to the version denoted in the version command near the beginning of the ado file and c(stata_version) is the underlying version installed - is this correct
    2. will the version command at the beginning of the file (in this case 9.1) effect how the ado file interpreter responds to the ustrregexra command, or is the version command simply a way to display an error if the user's version is too old, with no other effects?
    Thank you

  • #2
    Originally posted by Brent McSharry
    I am assuming c(version) relates to the version denoted in the version command near the beginning of the ado file and c(stata_version) is the underlying version installed - is this correct
    Yes, it is.

    Originally posted by Brent McSharry View Post
    will the version command at the beginning of the file (in this case 9.1) effect how the ado file interpreter responds to the ustrregexra command, or is the version command simply a way to display an error if the user's version is too old, with no other effects?
    Rather the latter. But I do not fully understand. Do you have version 9 installed and miss version 14 or higher to test your code? If so, that is fine. If you have version 14 or higher installed, then it is dangerous to specify version 9 in the ado file because you have no way of knowing whether your command really works in Stata 9 (Unicode support is by far not the only thing that has changed since version 9).

    Best
    Daniel
    Last edited by daniel klein; 13 Dec 2017, 15:47.

    Comment


    • #3
      Thank you Daniel.

      In answer to your question, I have a later version (13), but I know it is OK back to 9.1 based on historical use and also feedback from other users of the program.

      I guess it would be ideal to have a support matrix available somewhere, with a list of commands & functions and the Stata version they were created.

      Comment


      • #4
        As a sidelight, I have every version of Stata since V7 installed on my machine. There is need to uninstall old versions, as far as I can tell. It comes in handy for things like this.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        Stata Version: 17.0 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          Originally posted by Brent McSharry View Post
          I guess it would be ideal to have a support matrix available somewhere, with a list of commands & functions and the Stata version they were created.
          Not exactly a matrix, but

          Code:
          help whatsnew
          documents all relevant changes. Keep in mind that some commands and functions might have been available for quite some time but might have changed behavior over time. Usually, you do not need to worry about backwards compatibility because StataCorp worries for you. As long as you put the version under which you develop your programs at the top of your files, everything is supposed to go fine. There are exceptions. I remember recent discussions about changes to the way parameters are returned and stored after estimation commands in Stata 15 that could break some older user-written routines for postestimation.

          Best
          Daniel

          Comment


          • #6
            The shortest summary on one broad front is that the version command is not a time machine. The longer discussion at https://www.stata.com/support/faqs/p...stata-version/ may help here.

            Comment


            • #7
              Thank you very much for the link Nick - It now makes sense that the version command has 2 functions
              • Stop the program & provide the user with a message as to their version being too old to run the program (as above)
              • Ensure that when any Stata command or function has been altered between versions (arguments required, output), the older version of the command/function is used.
              • Stata DOES NOT disable commands which were introduced after the stated version, it only applies versioning to commands/functions which changed in implementation. This would help avoiding the exact problems outlined by Daniel regarding estimation commands in Stata >= 15
              whatsnew unfortunately is a long way from a support matrix, which would have each command, which version it was introduced and any versions it was changed in a single document or data source.

              Comment


              • #8
                It suddenly dawned on me that feature detection is commonly considered better programming practice, so that rather than
                Code:
                if c(stata_version)>=14 {
                    local markunits = ustrregexra("`markunits'", " +", ",")
                a better alternative might be to code
                Code:
                capture local markunits = ustrregexra("`markunits'", " +", ",")
                if (_rc!=0) {
                    //alternative code for when legacy Stata version does not have ustrregex range of functions
                    while (regexm("`markunits'", " +")) {
                        local markunits = regexr("`markunits'", " +", ",")
                    }
                }

                Comment

                Working...
                X