Statalist


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

st: subsetting a matrix by rowname and column name


From   Jacob Wegelin <[email protected]>
To   [email protected]
Subject   st: subsetting a matrix by rowname and column name
Date   Sat, 21 Mar 2009 17:43:39 -0400

The results below indicate that

(1) One can extract a cell from a matrix using the row and column names, but

(2) the value returned cannot be assigned to a scalar, only to a
one-by-one matrix. (See error below.)

(3) By contrast, when one extracts a cell from a matrix using row and
column *indices*, the value can be assigned to a scalar.

Is there some good reason for this? I'd ideally like to extract a
scalar by row and column name, since this would be less error-prone.

Thanks for any insights


. mat lis Betas3

Betas3[8,4]
                   glmeFixed  margOverYear  margOverNAME  margOverBOTH
     Intercept      1.076851     1.0446041      .9314962     .91146427
        Sex01F    -.10872187    -.10572026    -.09461439    -.09260798
       PL2Age2     -.0382385    -.03690922    -.03247097    -.03172728
Sex01FxPL2Age2    -.04284441    -.04173549    -.03758942     -.0368254
       PL2Age3    -.09794232     -.0954067    -.08586944    -.08411177
         MinCC    -.05824123    -.05666053    -.05079008    -.04972423
        PzCDrp    -.29371127    -.28608519    -.25737673     -.2520895
  MinCCxPzCDrp    -.03753782    -.03658906    -.03301933    -.03235626

. matrix tryThis=Betas3["Intercept","margOverBOTH"]

. mat lis tryThis

symmetric tryThis[1,1]
           margOverBOTH
Intercept     .91146427

. scalar tryThis2=Betas3["Intercept","margOverBOTH"]
matrix operators that return matrices not allowed in this context
r(509);

. scalar tryThis2=Betas3[1,4]

. di "tryThis2=" tryThis2
tryThis2=.91146427

. matrix tryThis3=Betas3[1,4]

. mat lis tryThis3

symmetric tryThis3[1,1]
           c1
r1  .91146427

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
*
*   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/



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