[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Balsky, Tanya" <tb2368@mail.gsb.columbia.edu> |

To |
<statalist@hsphsun2.harvard.edu> |

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

Date |
Tue, 14 Apr 2009 11:18:57 -0400 |

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/

**Follow-Ups**:**st: RE: Macro creates scalars-- how can I transfer them into a MATA matrix?***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**st: AW: Macro creates scalars-- how can I transfer them into a MATA matrix?***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**References**:**st: RE: AW: RE: foreach commands***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: spmap: color only selected areas?** - Next by Date:
**st: question about monte carlo study** - Previous by thread:
**st: RE: AW: RE: foreach commands** - Next by thread:
**st: AW: Macro creates scalars-- how can I transfer them into a MATA matrix?** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |