Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Naming rows of matrix


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Naming rows of matrix
Date   Fri, 22 Jul 2005 18:50:41 +0100

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/



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