Reading a caller’s local macros from a Stata ado program

Determine whether any mechanism exists for a Stata ado program to read local macros defined in its caller’s context, thereby enabling code invoked via the julia package’s jl ado wrapper to access caller-level locals when interfacing with Julia.

Background

The paper describes how the jl ado command wraps a C++ plugin to interface Stata with Julia. Because the plugin is invoked from within jl, any local macros written from Julia via SF_macro_save() appear in jl’s local scope rather than in the caller’s scope. As a workaround, jl tracks locals written via st_local() and copies them to the caller using the undocumented c_local command before exiting.

However, this workaround is one-directional: while writing locals from Julia to the caller is possible via this copying mechanism, reading the caller’s locals from within the jl context is not. The author explicitly notes that there is no known way for an ado program to read its caller’s local macros, leaving open whether any documented or undocumented interface could support this capability.

References

However, the same complication prevents one from reading Stata locals from Julia. The workaround just described only goes in one direction, because I know of no way for an ado program to read its caller's local macros.

Julia as a universal platform for statistical software development  (2404.09309 - Roodman, 2024) in Subsection 4.3, Limitations in accessing Stata objects