I have a function which is straightforward to implement in both the ado scripting language and mata. Let's call it func.
Currently, I have written func.ado which allows for the function to be used across my various .do and .ado files.
A problem has arisen. In another file (func2.ado), I have a bit of code where I define a mata associative array, then have a for loop, then change the associative array using results from the loop. In the loop, I would need to use the func.
It looks something like
mata
//1 define associative array
//2 loop
//3 use matrix info from loop to change associative array
end
As such, I have a mata loop which needs to use func. I am not sure how it would be best to resolve this. Here are my considered approaches:
1) Define func once more using mata. If I do this, is there a way I could do it once, and then use that definition across various files? Duplicating code is very bad practice, yet I am not sure if it is possible to avoid this problem for pure mata functions.
2) Call the ado version of func in the mata loop. I know it is possible to call mata while in the ado scripting language by coding "mata: XYZ" — is it possible to do something like the opposite?
3) Split up 1,2,3 as such:
mata
//1 define associative array
end
//2 loop
mata
//3 change associative array
end
by "sending" the associative array to STATA and then reimporting it in the second mata block. The analogy for matrices would be defining matrix m and invoking st_matrix("a",m) in the first block and then invoking m = st_matrix("m") in the second mata block. Is there a way to do this for associative arrays?
In the worst case, I can define func in mata in func2.ado and possibly again in other funcx.ado files if needed (duplicating code). However, if there is a way to resolve this issue more cleanly (via 1,2,3 or another method), I would be very grateful to implement this method.
Related Posts with Not duplicating Mata code / Using STATA in Mata
standard deviation and standard error as variablesHello every one, please i want to create variable which comes from standard deviation and standard …
sign restrictionsSuppose, I have a model like, -ASSET SALES =a*x1+b*CASH FLOWS. Kindly note the sign of dependent var…
Merlin packageI am assessing the merling package in Stata 14.2 for a "three-level survival model" and a "joint fra…
Bar and dot plots in a two-way graph commandDear All, I am looking to create a similar graph like the one herein attached which combines both b…
Identify missings in spellDear all, my data structure looks like this hhid id year 100 1 1 100 . 1 100 3 1 100 1 2…
Subscribe to:
Post Comments (Atom)
0 Response to Not duplicating Mata code / Using STATA in Mata
Post a Comment