Jacob Wegelin <[email protected]> :
Try:
sysuse auto, clear
g b=1
qui probit foreign mpg
mat b=e(b)
scalar b=el(matrix(b),1,colnumb(matrix(b),"mpg"))
di scalar(b)
di b
Note that matrices, scalars, and variables share the same namespace,
which often leads to cryptic error messages or huge mistakes for the
less careful (you may prefer to use a local instead to avoid this
problem). So say matrix(b) instead of b, and scalar(p) instead of p.
On Sat, Mar 21, 2009 at 5:43 PM, Jacob Wegelin <[email protected]> wrote:
> 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
*
* 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/