<>
Are you aware of the mata function
*************
st_numscalar()
*************
? I think that it fits your problem description...
BTW, why -syntax anything-? Seems to me you are passing integers to your
-prog-, some with rather restricted ranges. (Think rho: bounded by -1 and 1)
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Balsky, Tanya
Gesendet: Dienstag, 14. April 2009 17:19
An: [email protected]
Betreff: st: Macro creates scalars-- how can I transfer them into a MATA
matrix?
Dear Stata Listers,
Please excuse the beginner question-- I've searched the archives and
help files with no luck.
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.)
Thank you,
Tanya
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/
*
* 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/