Works like a charm--thanks!
On Wed, 20 Jul 2005, Scott Merryman wrote:
> What you need is the macro expansion operator `=exp' which provides the
> inline expression evaluator (see [P] macro).
>
> Here is one way to rename the rows as values of the variable
>
> sysuse auto, clear
> keep in 1/10
> mkmat mpg, mat(A)
>
> forv i = 1/10 {
> local temp`i' = mpg[`i']
> matname A `=`temp`i''', row(`i') e
> }
> matrix list A
>
> Hope this helps,
> Scott
>
>
> > -----Original Message-----
> > From: [email protected] [mailto:owner-
> > [email protected]] On Behalf Of Herb Smith
> > Sent: Wednesday, July 20, 2005 6:09 PM
> > To: [email protected]
> > Subject: st: Naming rows of matrix
> >
> > Suppose I want to label the 12th row of a matrix: 1982-83
> >
> > If I assign this value to a local macro, and then use matname, everything
> > is fine:
> >
> > . local tmp12a="1982-83"
> > . matname matrixname `tmp12a', row(12) e
> >
> > i.e., when I list the matrix, the label is 1982-83
> >
> > This is a silly way to do things, but now consider the problem where a
> > label such as 1982-83 is the 12th case of a variable such
> as
> > var15 .
> >
> > . local tmp12b=var15[12]
> >
> > assigns the string 1982-83 to the new local macro, in the
> > sense that
> >
> > . dis `tmp12b'
> >
> > displays 1982-83
> >
> > but the command
> >
> > . matname matrixname `tmp12b', row(12) e
> >
> > results in the label: var15[12] being assigned to the 12th row of
> > the matrix--not the string associated with this element.
> >
> > Is there a workaround for this?
> >
> > Or, more generally, is there a simple way to assign the values of a
> > variable to the corresponding rows of a matrix (which is what I am trying
> > to do here)?
> >
> > Thanks in advance,
> >
> > --Herb Smith
> >
> >
>
>
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/