Announcement

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

  • frames and backward compatability of programs

    Thought I would share this, for anyone trying to maintain backward compatibility in programs they write:

    In trying to update a program to take advantage of frames, I find that one form in particular breaks under older versions of Stata.

    In Stata 15 this breaks:
    Code:
    sysuse auto
    
    if c(stata_version) >= 16 {
        frame copy default auto
        frame auto {
            generate gpm = 1/mpg
            summarize gpm
        }
    }
    else {
        display "What? Me worry?"
    }
    However, this will run:
    Code:
    sysuse auto
    
    if c(stata_version) >= 16 {
        frame copy default auto
        frame auto: generate gpm = 1/mpg
        frame auto: summarize gpm
    }
    else {
        display "What? Me worry?"
    }
    Doug Hemken
    SSCC, Univ. of Wisc.-Madison

  • #2
    Due to the way our University licenses Stata, it looks like I've got 6 weeks left to be able to check whether my updates break anything ....
    Doug Hemken
    SSCC, Univ. of Wisc.-Madison

    Comment


    • #3
      That seems to me to be a bug in Stata. But if so it is a bug that may never get fixed, because it is a bug in the now outdated Stata 15. I would report it to Stata Tech Support and hope that they would add a fix. I tried it in Stata 14 and got the same error, so if you are working with others hopefully their version of Stata isn't too ancient.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 19.5 MP (2 processor)

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

      Comment


      • #4
        This appears to be a problem with the syntax parser struggling to find the matching close (curly)brace. My guess is that Stata versions prior to 16 are not aware of the new frame commands and therefore somehow miss the second open (curly)brace, following frame, in the code.

        Anyway, one strategy that I like (and I think it is good programming practice, too) is a caller program that forks to subroutines (cf. merge.ado). Something like this should work

        Code:
        program mycmd
            version 15
            
            if (c(stata_version) < 16) {
                mycmd_old `0'
                exit
                // NotReached
            }
            
            version 16
        
            frame ... {
            
            }
        end
        
        program mycmd_old
            display "What, me worry?"
        end
        exit
        When you write ado-files, note that you can even do something like this

        Code:
        program mycmd
            version 15
            
            if (c(stata_version) < 16) _mycmd   `0'
            else                       _mycmd16 `0'  
        end
        
        program _mycmd
            display "What, me worry?"
        end
        
        if (c(stata_version) < 16) exit // <- do not even load the programs below
        
        program _mycmd16
            version 16
            frame ... {
            
            }
        end
        exit
        where you do not even load the new version of your command if it is called using older versions of Stata (cf. tuples.ado, SSC).

        Best
        Daniel

        Comment


        • #5
          Daniel,

          Interesting suggestion. This would work well for a program that is keeping the same syntax (no new options, for example), but is being reworked for processing efficiency. Then you could just reuse your existing code without altering it for the "old" sub-routine.

          If you are introducing a new option, you will have to update the error handling in the old code. You could end up with a lot of code duplicated across the two versions, depending on how far you went in building sub-routines for the original version.
          Doug Hemken
          SSCC, Univ. of Wisc.-Madison

          Comment


          • #6
            Of course, I could just do the new error handling prior to calling the old code ....

            btw I think you mean "eg" not "cf"? See https://blog.apastyle.org/files/apa-...ns-table-2.pdf
            Doug Hemken
            SSCC, Univ. of Wisc.-Madison

            Comment


            • #7
              Originally posted by Doug Hemken View Post
              Of course, I could just do the new error handling prior to calling the old code ....

              btw I think you mean "eg" not "cf"? See https://blog.apastyle.org/files/apa-...ns-table-2.pdf
              Both correct; although it is: e.g. not eg

              Best
              Daniel

              Comment

              Working...
              X