Hi All,

Yesterday a user made an issue on the -domin- (SSC) package's GitHub page noting that they are getting an error that a Mata function was complied in Stata v17 and that older versions of Stata cannot use it.

I had never come across this before and couldn't find any documentation on this as a change for developers who use Mata.

I have access to Stata versions back to v12 but this behavior can be observed with versions as recent as v16 as well with a .mlib compiled with v17. I have an example below that is intended to be reproducible. I've included the paths to all the files for completeness. I did this on a Windows machine with Stata 17 MP and Stata 16 SE.

Note that the .mlib complied with Stata v17 fails to run when called with v16. The .mlib compiled with v16 works with both v16 and v17 however.

My question is whether there is a way to make an .mlib back compatible using v17 without using compiling using an older version of Stata.

- joe

Code:
. version 17

. 
. clear all

. 
. cd "C:\Users\jluchman\Documents\Statalist"
C:\Users\jluchman\Documents\Statalist

. 
. **# Define .mata file for compliation
. file open mata_fn using st_mata.mata, write replace

. 
. file write mata_fn "mata:" _newline(2)

. 
. file write mata_fn "void say_something() {" _newline(2)

. 
. file write mata_fn `"printf("looks like it works")"' _newline(2)

. 
. file write mata_fn "}" _newline(2)

. 
. file write mata_fn "end" 

. 
. file close mata_fn

. 
. **# Define .do that compiles
. file open lm_bld using lmbuild_it.do, write replace

. 
. file write lm_bld "clear all" _newline(2)

. 
. file write lm_bld "do C:\Users\jluchman\Documents\Statalist\st_mata.mata" _newline(2)

. 
. file write lm_bld `"lmbuild lb_statalist, replace dir(C:\Users\jluchman\Documents\Statalist\)"'

. 
. file close lm_bld

. 
. **# Define .do that calls say_something()
. file open say using do_say.do, write replace

. 
. file write say `"adopath + "C:\Users\jluchman\Documents\Statalist\""' _newline(2)

. 
. file write say "mata: mata mlib index" _newline(2)

. 
. file write say "mata: say_something()"

. 
. file close say

. 
. **# Call V17 to compile
. shell "C:\Program Files\Stata17/StataMP-64" /e do "C:\Users\jluchman\Documents\Statalist\lmbuild_it.do"

. 
. copy lmbuild_it.log lmbuild_it17.log, replace

. 
. file open bld using lmbuild_it17.log, read

. 
. local linenum = 0

. 
. file read bld line

. 
. while r(eof) == 0 {
  2.         
.         local linenum = `linenum' + 1
  3.         if !inrange(`linenum', 12, 16) display %4.0f `linenum' _asis `"  `macval(line)'"'
  4.         file read bld line
  5.         
. }
   1  
   2    ___  ____  ____  ____  ____ ®
   3   /__    /   ____/   /   ____/      17.0
   4  ___/   /   /___/   /   /___/       MP—Parallel Edition
   5  
   6   Statistics and Data Science       Copyright 1985-2021 StataCorp LLC
   7                                     StataCorp
   8                                     4905 Lakeway Drive
   9                                     College Station, Texas 77845 USA
  10                                     800-STATA-PC        https://www.stata.com
  11                                     979-696-4600        stata@stata.com
  17  
  18  Notes:
  19        1. Stata is running in batch mode.
  20        2. Unicode is supported; see help unicode_advice.
  21        3. More than 2 billion observations are allowed; see help obs_advice.
  22        4. Maximum number of variables is set to 5,000; see help set_maxvar.
  23  
  24  . do C:\Users\jluchman\Documents\Statalist\lmbuild_it.do 
  25  
  26  . clear all
  27  
  28  . 
  29  . do C:\Users\jluchman\Documents\Statalist\st_mata.mata
  30  
  31  . mata:
  32  ------------------------------------------------- mata (type end to exit) -----
  33  : 
  34  : void say_something() {
  35  > 
  36  > printf("looks like it works")
  37  > 
  38  > }
  39  
  40  : 
  41  : end
  42  -------------------------------------------------------------------------------
  43  
  44  . 
  45  end of do-file
  46  
  47  . 
  48  . lmbuild lb_statalist, replace dir(C:\Users\jluchman\Documents\Statalist\)
  49  (1 function added)
  50  existing library C:\Users\jluchman\Documents\Statalist\lb_statalist.mlib replac
  51  > ed
  52  
  53  . 
  54  end of do-file

. 
. file close bld

. 
. **# Call V17 do
. shell "C:\Program Files\Stata17/StataMP-64" /e do "C:\Users\jluchman\Documents\Statalist\do_say.do"

. 
. copy do_say.log do_say17_cpl17.log, replace

. 
. file open bld using do_say17_cpl17.log, read

. 
. local linenum = 0

. 
. file read bld line

. 
. while r(eof) == 0 {
  2.         
.         local linenum = `linenum' + 1
  3.         if !inrange(`linenum', 12, 16) display %4.0f `linenum' _asis `"  `macval(line)'"'
  4.         file read bld line
  5.         
. }
   1  
   2    ___  ____  ____  ____  ____ ®
   3   /__    /   ____/   /   ____/      17.0
   4  ___/   /   /___/   /   /___/       MP—Parallel Edition
   5  
   6   Statistics and Data Science       Copyright 1985-2021 StataCorp LLC
   7                                     StataCorp
   8                                     4905 Lakeway Drive
   9                                     College Station, Texas 77845 USA
  10                                     800-STATA-PC        https://www.stata.com
  11                                     979-696-4600        stata@stata.com
  17  
  18  Notes:
  19        1. Stata is running in batch mode.
  20        2. Unicode is supported; see help unicode_advice.
  21        3. More than 2 billion observations are allowed; see help obs_advice.
  22        4. Maximum number of variables is set to 5,000; see help set_maxvar.
  23  
  24  . do C:\Users\jluchman\Documents\Statalist\do_say.do 
  25  
  26  . adopath + "C:\Users\jluchman\Documents\Statalist\"
  27    [1]  (BASE)      "C:\Program Files\Stata17\ado\base/"
  28    [2]  (SITE)      "C:\Program Files\Stata17\ado\site/"
  29    [3]              "."
  30    [4]  (PERSONAL)  "C:\Users\jluchman\ado\personal/"
  31    [5]  (PLUS)      "c:\ado\plus/"
  32    [6]  (OLDPLACE)  "c:\ado/"
  33    [7]              "C:\Users\jluchman\Documents\Statalist\"
  34  
  35  . 
  36  . mata: mata mlib index
  37  .mlib libraries to be searched are now
  38      lmatabase;lmataado;lmatabma;lmatacollect;lmataerm;lmatafc;lmatagsem;lmatala
  39  > sso;lmatamcmc;lmatameta;lmatami;lmatamixlog;lmatanumlib;lmataopt;lmatapath;lm
  40  > atapostest;lmatapss;lmatasem;lmatasp;lmatasvy;lmatatab;lb_statalist;lb_domina
  41  > nce;lmoremata;lmoremata10;lmoremata11;lmoremata14
  42  
  43  . 
  44  . mata: say_something()
  45  looks like it works
  46  . 
  47  end of do-file

. 
. file close bld

. 
. **# Call V16 do
. shell "C:\Program Files\Stata16/StataSE-64" /e do "C:\Users\jluchman\Documents\Statalist\do_say.do"

. 
. copy do_say.log do_say16_cpl17.log, replace

. 
. file open bld using do_say16_cpl17.log, read

. 
. local linenum = 0

. 
. file read bld line

. 
. while r(eof) == 0 {
  2.         
.         local linenum = `linenum' + 1
  3.         if !inrange(`linenum', 12, 16) display %4.0f `linenum' _asis `"  `macval(line)'"'
  4.         file read bld line
  5.         
. }
   1  
   2    ___  ____  ____  ____  ____ (R)
   3   /__    /   ____/   /   ____/
   4  ___/   /   /___/   /   /___/   16.1   Copyright 1985-2019 StataCorp LLC
   5    Statistics/Data analysis            StataCorp
   6                                        4905 Lakeway Drive
   7       Special Edition                  College Station, Texas 77845 USA
   8                                        800-STATA-PC        https://www.stata.com
   9                                        979-696-4600        stata@stata.com
  10                                        979-696-4601 (fax)
  11  
  17  Notes:
  18        1. Stata is running in batch mode.
  19        2. Unicode is supported; see help unicode_advice.
  20        3. Maximum number of variables is set to 5,000; see help set_maxvar.
  21  
  22  . do C:\Users\jluchman\Documents\Statalist\do_say.do 
  23  
  24  . adopath + "C:\Users\jluchman\Documents\Statalist\"
  25    [1]  (BASE)      "C:\Program Files\Stata16\ado\base/"
  26    [2]  (SITE)      "C:\Program Files\Stata16\ado\site/"
  27    [3]              "."
  28    [4]  (PERSONAL)  "C:\Users\jluchman\ado\personal/"
  29    [5]  (PLUS)      "c:\ado\plus/"
  30    [6]  (OLDPLACE)  "c:\ado/"
  31    [7]              "C:\Users\jluchman\Documents\Statalist\"
  32  
  33  . 
  34  . mata: mata mlib index
  35  .mlib libraries to be searched are now
  36      lmatabase;lmataado;lmataerm;lmatafc;lmatagsem;lmatalasso;lmatamcmc;lmatamet
  37  > a;lmatami;lmatamixlog;lmatanumlib;lmataopt;lmatapath;lmatapostest;lmatapss;lm
  38  > atasem;lmatasp;lmatasvy;lmatatab;lb_statalist;lb_dominance;lmoremata;lmoremat
  39  > a10;lmoremata11;lmoremata14
  40  
  41  . 
  42  . mata: say_something()
  43  (say_something() in lb_statalist, compiled by Stata 17.0, is too new to be run
  44  by this version of Stata and so was ignored)
  45                   <istmt>:  3499  say_something() not found
  46  r(3499);
  47  
  48  end of do-file
  49  r(3499);

. 
. file close bld

. 
. **# Call V16 to compile
. shell "C:\Program Files\Stata16/StataSE-64" /e do "C:\Users\jluchman\Documents\Statalist\lmbuild_it.do"

. 
. copy lmbuild_it.log lmbuild_it16.log, replace

. 
. file open bld using lmbuild_it16.log, read

. 
. local linenum = 0

. 
. file read bld line

. 
. while r(eof) == 0 {
  2.         
.         local linenum = `linenum' + 1
  3.         if !inrange(`linenum', 12, 16) display %4.0f `linenum' _asis `"  `macval(line)'"'
  4.         file read bld line
  5.         
. }
   1  
   2    ___  ____  ____  ____  ____ (R)
   3   /__    /   ____/   /   ____/
   4  ___/   /   /___/   /   /___/   16.1   Copyright 1985-2019 StataCorp LLC
   5    Statistics/Data analysis            StataCorp
   6                                        4905 Lakeway Drive
   7       Special Edition                  College Station, Texas 77845 USA
   8                                        800-STATA-PC        https://www.stata.com
   9                                        979-696-4600        stata@stata.com
  10                                        979-696-4601 (fax)
  11  
  17  Notes:
  18        1. Stata is running in batch mode.
  19        2. Unicode is supported; see help unicode_advice.
  20        3. Maximum number of variables is set to 5,000; see help set_maxvar.
  21  
  22  . do C:\Users\jluchman\Documents\Statalist\lmbuild_it.do 
  23  
  24  . clear all
  25  
  26  . 
  27  . do C:\Users\jluchman\Documents\Statalist\st_mata.mata
  28  
  29  . mata:
  30  ------------------------------------------------- mata (type end to exit) -----
  31  : 
  32  : void say_something() {
  33  > 
  34  > printf("looks like it works")
  35  > 
  36  > }
  37  
  38  : 
  39  : end
  40  -------------------------------------------------------------------------------
  41  
  42  . 
  43  end of do-file
  44  
  45  . 
  46  . lmbuild lb_statalist, replace dir(C:\Users\jluchman\Documents\Statalist\)
  47  (1 function added)
  48  existing library C:\Users\jluchman\Documents\Statalist\lb_statalist.mlib replac
  49  > ed
  50  
  51  . 
  52  end of do-file

. 
. file close bld

. 
. 
. **# Call V17 do
. shell "C:\Program Files\Stata17/StataMP-64" /e do "C:\Users\jluchman\Documents\Statalist\do_say.do"

. 
. copy do_say.log do_say17_cpl16.log, replace

. 
. file open bld using do_say17_cpl16.log, read

. 
. local linenum = 0

. 
. file read bld line

. 
. while r(eof) == 0 {
  2.         
.         local linenum = `linenum' + 1
  3.         if !inrange(`linenum', 12, 16) display %4.0f `linenum' _asis `"  `macval(line)'"'
  4.         file read bld line
  5.         
. }
   1  
   2    ___  ____  ____  ____  ____ ®
   3   /__    /   ____/   /   ____/      17.0
   4  ___/   /   /___/   /   /___/       MP—Parallel Edition
   5  
   6   Statistics and Data Science       Copyright 1985-2021 StataCorp LLC
   7                                     StataCorp
   8                                     4905 Lakeway Drive
   9                                     College Station, Texas 77845 USA
  10                                     800-STATA-PC        https://www.stata.com
  11                                     979-696-4600        stata@stata.com
  17  
  18  Notes:
  19        1. Stata is running in batch mode.
  20        2. Unicode is supported; see help unicode_advice.
  21        3. More than 2 billion observations are allowed; see help obs_advice.
  22        4. Maximum number of variables is set to 5,000; see help set_maxvar.
  23  
  24  . do C:\Users\jluchman\Documents\Statalist\do_say.do 
  25  
  26  . adopath + "C:\Users\jluchman\Documents\Statalist\"
  27    [1]  (BASE)      "C:\Program Files\Stata17\ado\base/"
  28    [2]  (SITE)      "C:\Program Files\Stata17\ado\site/"
  29    [3]              "."
  30    [4]  (PERSONAL)  "C:\Users\jluchman\ado\personal/"
  31    [5]  (PLUS)      "c:\ado\plus/"
  32    [6]  (OLDPLACE)  "c:\ado/"
  33    [7]              "C:\Users\jluchman\Documents\Statalist\"
  34  
  35  . 
  36  . mata: mata mlib index
  37  .mlib libraries to be searched are now
  38      lmatabase;lmataado;lmatabma;lmatacollect;lmataerm;lmatafc;lmatagsem;lmatala
  39  > sso;lmatamcmc;lmatameta;lmatami;lmatamixlog;lmatanumlib;lmataopt;lmatapath;lm
  40  > atapostest;lmatapss;lmatasem;lmatasp;lmatasvy;lmatatab;lb_statalist;lb_domina
  41  > nce;lmoremata;lmoremata10;lmoremata11;lmoremata14
  42  
  43  . 
  44  . mata: say_something()
  45  looks like it works
  46  . 
  47  end of do-file

. 
. file close bld

. 
. **# Call V16 do
. shell "C:\Program Files\Stata16/StataSE-64" /e do "C:\Users\jluchman\Documents\Statalist\do_say.do"

. 
. copy do_say.log do_say16_cpl16.log, replace

. 
. file open bld using do_say16_cpl16.log, read

. 
. local linenum = 0

. 
. file read bld line

. 
. while r(eof) == 0 {
  2.         
.         local linenum = `linenum' + 1
  3.         if !inrange(`linenum', 12, 16) display %4.0f `linenum' _asis `"  `macval(line)'"'
  4.         file read bld line
  5.         
. }
   1  
   2    ___  ____  ____  ____  ____ (R)
   3   /__    /   ____/   /   ____/
   4  ___/   /   /___/   /   /___/   16.1   Copyright 1985-2019 StataCorp LLC
   5    Statistics/Data analysis            StataCorp
   6                                        4905 Lakeway Drive
   7       Special Edition                  College Station, Texas 77845 USA
   8                                        800-STATA-PC        https://www.stata.com
   9                                        979-696-4600        stata@stata.com
  10                                        979-696-4601 (fax)
  11  
  17  Notes:
  18        1. Stata is running in batch mode.
  19        2. Unicode is supported; see help unicode_advice.
  20        3. Maximum number of variables is set to 5,000; see help set_maxvar.
  21  
  22  . do C:\Users\jluchman\Documents\Statalist\do_say.do 
  23  
  24  . adopath + "C:\Users\jluchman\Documents\Statalist\"
  25    [1]  (BASE)      "C:\Program Files\Stata16\ado\base/"
  26    [2]  (SITE)      "C:\Program Files\Stata16\ado\site/"
  27    [3]              "."
  28    [4]  (PERSONAL)  "C:\Users\jluchman\ado\personal/"
  29    [5]  (PLUS)      "c:\ado\plus/"
  30    [6]  (OLDPLACE)  "c:\ado/"
  31    [7]              "C:\Users\jluchman\Documents\Statalist\"
  32  
  33  . 
  34  . mata: mata mlib index
  35  .mlib libraries to be searched are now
  36      lmatabase;lmataado;lmataerm;lmatafc;lmatagsem;lmatalasso;lmatamcmc;lmatamet
  37  > a;lmatami;lmatamixlog;lmatanumlib;lmataopt;lmatapath;lmatapostest;lmatapss;lm
  38  > atasem;lmatasp;lmatasvy;lmatatab;lb_statalist;lb_dominance;lmoremata;lmoremat
  39  > a10;lmoremata11;lmoremata14
  40  
  41  . 
  42  . mata: say_something()
  43  looks like it works
  44  . 
  45  end of do-file

. 
. file close bld

.