[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Herb Smith <[email protected]> |

To |
[email protected] |

Subject |
Re: st: RE: RE: Naming rows of matrix |

Date |
Fri, 22 Jul 2005 14:52:49 -0400 (EDT) |

Thanks. In fact, that is exactly what I ended up doing. The previous step was just left in as I was trying to de-bug things... --Herb Professor of Sociology and Director, Population Studies Center 3718 Locust Walk CR University of Pennsylvania Philadelphia, PA 19104-6298 [email protected] 215.898.7768 (office) 215.898.2124 (fax) On Fri, 22 Jul 2005, Nick Cox wrote: > Scott's loop can be simplified to > > forv i = 1/10 { > matname A `= mpg[`i']'', row(`i') e > } > > Nick > [email protected] > > Scott Merryman > > > 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 > > Herb Smith > > > > 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)? > > * > * 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/

**References**:**st: RE: RE: Naming rows of matrix***From:*"Nick Cox" <[email protected]>

- Prev by Date:
**st: How to capture record info where "something" about the record is true?** - Next by Date:
**st: RE: Need help w serrbar format** - Previous by thread:
**st: RE: RE: Naming rows of matrix** - Next by thread:
**st: RE: Number format** - Index(es):

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