Announcement

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

  • How to put a mata ml evaluator in a SSC package

    I have two files: File1 (ado) for an estimation command, and File2 (mata) for the mata based ml estimation function. File2 has mata mlib lines to create a library, and when I compile File2 on my computer, File1 works well. File1 would only work if File2 is run at least once by the user.

    I want to make this program available to other users on SSC, and I know about how to upload ado files on SSC, but I am not sure how to upload an ado file on SSC that relies on the compilation of a mata file. How is it generally done? Do you put those two files in a folder and a readme text file to tell the user to compile the mata file first? Or, when you install a package from SSC, does it automatically compile the mata file for the user so that the ado file would work without a need to manually compile the mata file first? Or do you do something in File1 so that File1 would compile File2 when File1 is run by the user?

    Below is a simplified example:
    Code:
    // File1 (ado)
    ...
    program Estimate, eclass
    ...
    ml model lf myprob() (...)
    ml max
    ...
    end
    
    
    // File2 (mata)
    mata:
    void myprob(transmorphic scalar ML, real rowvector b, real colvector lnfj) {
        depvar = moptimize_util_depvar(ML, 1)
        xb = moptimize_util_xb(ML,b,1)
        lnfj = ...
    }
    end
    mata: mata mlib create lmyprob, dir(PLUS) replace
    mata: mata mlib add lmyprob myprob(), dir(PLUS)

  • #2
    Why do want to not pre-compile the evaluator and ship the compiled mlib?
    You could also add in the beginning of your code a check for the existence of the mlib-file and compile it during the first call of your evaluator. Something like
    Code:
    // File1 (ado)
    ...
    program Estimate, eclass
    ...
    capture findfile lmyprob.mlib
    if !rc do File2.mata
    ml model lf myprob() (...)
    ml max
    ...
    end

    Comment


    • #3
      As Sven Kristjan mentioned, you can add smaller Mata routines at the bottom of an .ado file. If the Mata routines become larger, then I prefer to add the compiled Mata library together with the source. The compiled library makes sure that everybody can run the program directly, just as any other Stata program. The source-file if for those who don't like pre-compiled programs from the internet, and for those who want to program similar things and wonder how I did things.
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment

      Working...
      X