Announcement

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

  • abbreviated command in .ado file

    How can I add the option of abbreviated command to an .ado file?
    Let's say my program is called something.ado and runs well with

    something varlist

    and I want also to run with

    som varlist

  • #2
    Unless you want to mess with Stata's deeper internals, which you really should not, you can setup a second ado-file, som.ado

    Code:
    program som
        // version intentionally omitted
        something `0'
    end
    Abbreviations are generally not allowed for programs uploaded to the SSC. Moreover, the more ado-files you have for the same underlying command/code, the more likely you will run into problems with ambiguous names. For example, som might be fine, so is not, as it is an abbreviation for Stata's sort. In short, having abbreviated names for personal or community-contributed programs is not a good idea.

    Comment


    • #3
      I usually agree with daniel klein but not so much here. I've sometimes (only occasionally, but more than never) allowed abbreviations of the names of my commands -- which as far as I know is only possible by defining multiple ado-files. The need to watch out for clashes with official names is absolute but it will bite you long before you can use such commands. That is: suppose I implement foobar and also foo where the definition of foo could be as simple as

      Code:
      /// not daniel klein 
      program foo 
             foobar `0' 
      end
      Now suppose foo is already allowed as (an abbreviation of) an official command. Then the user command foo will never be executed in preference, and so the idea fails on ignition, not even lift-off. (There is some small print here, of the kind daniel is alluding to, but like him I won't go into detail for fear of leading user-programmers into temptations they should want to resist any way.)

      I'd agree with this: allowing multiple names for your commands increases the probability of a clash with other community-contributed commands.

      The problems here are small but explicable. Thus I have had my own commands being broken by a later official command and by a later command written by another user. Small deal either way.

      Comment


      • #4
        Thanks a lot Daniel and Nick. I understand now why Stata does not give a simple capitalized option as "program SOMething" to later use "som" as an abbreviation. My intentions was not to create many .ado files, but rather to use gettoken and make a program like the one below so I can keep "something" as the name of the program:
        Code:
         program define something    
         gettoken subcmd 0 : 0   
            
         if ("`subcmd'" == "som" | "`subcmd'"=="something") {    
         myareg `subcmd' `0' // Is this neccesary?   
         ... // main code here   
         }  
         end
        Does this have sense?

        Comment


        • #5
          That lets you type

          Code:
          something something ..
          .

          or

          Code:
          something som ...
          which may be close to what you want.

          I'd look inside the code for commands that allow abbreviations for subcommands to see how they do it. I will mention missings from the Stata Journal because it is familiar to me, but I learned the basic trickery from President Emeritus William Gould.

          Code:
          search dm0085_2
          Backing up:

          If you want a command you write to have an alternative shorter name, you need to define that as a different command, but that can be done easilyl See #3 again.

          If you want a command you write to support alternative shorter names for subcommands, you can do that within the main program.



          Comment


          • #6
            Originally posted by Nick Cox View Post
            I'd look inside the code for commands that allow abbreviations for subcommands to see how they do it. I will mention missings from the Stata Journal because it is familiar to me, but I learned the basic trickery from President Emeritus William Gould.
            I cannot be 100 percent certain, but I am pretty sure that I have learned that basic trickery that is used in missings.ado from Nick Cox.

            Comment


            • #7
              That's fine. I have explained bits of statistics to thousands of geography students, most of whom have probably forgotten most of what I said, and I invented none of it, but it's what we do.

              Comment

              Working...
              X