Announcement

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

  • ado file programs in memory

    Dear all

    I recently came across a strange problem. Programs saved in ado files within the ado path are not loaded when Stata starts.

    For example, assume that i have an ado file named hello.ado in the PLUS directory:

    Code:
    program define hello
    
    program's content
    
    end
    
    
    program define bye
    
    program's contents
    
    end
    Now if i type in Stata bye i get the following error:

    Code:
    unrecognized command:  bye
    r(199);
    After trial and error, i discovered that if i put program bye into a separate ado file (bye.ado) then it runs as expected.

    Is it not possible to automatically load all programs in an ado file (in this example hello.ado), which is in the ado path?

    Thank you.

  • #2
    In this case bye is being defined as a subprogram or subroutine of hello, given you have called your file hello.ado.

    The fact that you don't call it from hello is not fatal, but neither that fact nor any other implies that bye will be recognised as a separate command in its own right. .

    Multiple programs can be defined in a single ado file but at most one will be defined in its own right; all others will be subroutines. Given that this is how subroutines are defined, separate command definitions require separate .ado files.

    Comment


    • #3
      Point well taken. Is there however a way to automatically load the subroutines into memory? What if i include program bye in hello without any arguments?

      Code:
      program define hello
      
      bye
      program's content  
      
      end  
      
      
      program define bye  
      
      program's contents  
      
      end
      Will this be loaded on start up then?

      Comment


      • #4
        If you call hello, it will be able to use bye. But you will never be able to call bye without a file called bye.ado existing somewhere (if I'm not mistaken).

        Comment


        • #5
          Exploring the advice from Nick and Jesse led me to understand that the program you define as bye within hello.ado is shown by the program dir command as hello.bye and cannot be called as either by or hello.bye from your command line; it can only be called as bye from within the program hello; hence its status as a subcommand.

          Comment


          • #6
            Reply to #3: That coding doesn't affect the principle one bit. As you're defining the programs bye is a subroutine of hello.

            Comment

            Working...
            X