st: RE: Macro creates scalars-- how can I transfer them into a MATA matrix?

st: RE: Macro creates scalars-- how can I transfer them into a MATA matrix?

Date

Tue, 14 Apr 2009 16:39:55 +0100

Much depends on how you use this program (not macro), and you give no
precise examples of that. Precise means you say exactly what you type
and exactly what Stata did, not give an indirect report.
It is written to use other programs
L4_co_wx
L2_co_wx
L2
L4_co_xw
L2_co_xw
on which there is also no information.
But there is no reason to put locals or scalars in variables before
reading them into Mata. Mata can access Stata locals and scalars
directly.
Nick
n.j.cox@durham.ac.uk
Balsky, Tanya
I have a macro (code below) that should spit out 6 scalars. The scalars
each contain one numeric value. I would like to create a vector in MATA
consisting of each of the 6 values. My thoughts on how to do this was to
turn each scalar into a numeric variable then use st_data() in MATA to
form the matrix. However, nothing I've tried has successfully converted
the scalar to usable numeric variable. I've tried generating a variable
equal to the scalar, creating a local scalar equal to the macro scalar
and then generating a variable it's equal to, and several other things,
but haven't found anything that holds the value, rather than 0 or null.
(When I display the scalar value from the macro, it isn't 0 or null.)
program define T4_co, rclass
syntax anything
local w "(`1')" /* w = weight on the gamma=1 term in the X
variable */
local alpha "(`2')" /* alpha = probability that gamma=1 */
local rho "(`3')" /* correlation of Y and Z */
local sigmaD "(`4')" /* std dev of D */
local sigmaY "(`5')" /* std dev of Y */
local sigmaZ "(`6')" /* std dev of Z */
L4_co_wx `w' `alpha' `rho' `sigmaD' `sigmaY' `sigmaZ'
local L4_co_wx = r(L4_co_wx)
L2_co_wx `w' `alpha' `rho' `sigmaD' `sigmaY' `sigmaZ'
local L2_co_wx = r(L2_co_wx)
L2 1 `alpha' `sigmaD' `sigmaY'
local L2_w = r(L2)
return scalar L2_co_wx = `L2_co_wx'
return scalar L4_co_wx = `L4_co_wx'
return scalar T4_co_wx = `L4_co_wx'/`L2_w'
L4_co_xw `w' `alpha' `rho' `sigmaD' `sigmaY' `sigmaZ'
local L4_co_xw = r(L4_co_xw)
L2_co_xw `w' `alpha' `rho' `sigmaD' `sigmaY' `sigmaZ'
local L2_co_xw = r(L2_co_xw)
L2 `w' `alpha' `sigmaD' `sigmaZ'
local L2_x = r(L2)
return scalar L2_co_xw = `L2_co_xw'
return scalar L4_co_xw = `L4_co_xw'
return scalar T4_co_xw = `L4_co_xw'/`L2_x'
end
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/