I am trying to do something very simple. I just want to get the max of a set of numbers stored in a local macro `vcnumbers`. I converted this set of numbers into a matrix in Mata, got the max, and then sent it back to Stata in a local macro `maxvc`. As you can see in the replicable example below, the number obtained in Mata (20191018165607) is different from the one sent to Stata (20200000000000). Do you know how can I get the right number back in Stata? I guess I am doing something wrong by converting to reals and then to strings again but, up to my knowledge, there is no other way to export local macros in Stata from Mata, is that right?

Code:

local vcnumbers `" "20190812180416" "20190819173838" "20191008105614" "20191008140743" "20191008141755" "20191018165607" "' mata { VC = strtoreal(tokens(`"`vcnumbers'"')) printf("%15.0f\n" , max(VC)) st_local("maxvc", strofreal(max(VC))) } disp %15.0f `maxvc'

Thank you so much!

PS: In case you're wondering why the local macro `vcnumbers` is stored in that way, it is because it comes from

Code:

local vcnumbers: dir "." files "zzz*" local vcnumbers: subinstr local vcnumbers "zzz" "", all

Code:

capture mata mata drop returnpointer() mata function returnpointer() { pointer matrix p string matrix ss,ls real matrix sr,lr p=J(4,1,NULL) ss="a","b" ls="a","b","c" sr=1,2 lr=1,2,3,4 p[1]=&ss p[2]=&ls p[3]=&sr p[4]=&lr return(p) } for (j=1;j<=4;j++) { *returnpointer()[j] } endwhich gives this output

Code:

: : for (j=1;j<=4;j++) { > *returnpointer()[j] > } 1 2 +---------+ 1 | a b | +---------+ 1 2 3 +-------------+ 1 | a b c | +-------------+ 1 2 +---------+ 1 | 1 2 | +---------+ 1 2 3 4 +-----------------+ 1 | 1 2 3 4 | +-----------------+ :