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
Using Stata with Shared Cloud Apps: OneDrive or DropboxHello, I have been running into issues with using Stata with shared folders in OneDrive. With my u…
How to Categorize float variableI want to Categorize float variable which has letters as its elements. Elements: Horse, Camel, Car,…
Stata equivalent to SPSSHello friends I hope you are well. I saw this video on youtube on how to normalize your data on SPS…
Question regarding interpretation of interaction effect in logistic regressionHello, I was wondering if it would be possible to get some feedback on my interpretation of interac…
Difference in Difference omitted treatment indicatorHello! I want to analyse how a market entry of a specific app is associated with a change in the dow…
Subscribe to:
Post Comments (Atom)
0 Response to Not duplicating Mata code / Using STATA in Mata
Post a Comment