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

st: RE: column and row naming


From   "Jann, Ben" <[email protected]>
To   <[email protected]>
Subject   st: RE: column and row naming
Date   Thu, 4 Sep 2003 11:43:39 +0200

John writes:
> I've got two related questions regarding column and row names.
> (1) How can I replace the 'jth' column name only?
> (2) How can I save as a macro the 1st j column names from a matrix?

As far as I know, there are no specific functions for such purposes and
you have to use some work arounds.

(1) To change the name of row 2 to "whatever":

 mat a=(1 \ 2 \ 3)
 forv i=1/`=rowsof(a)' {
  if `i'==2 local rnames "`rnames' whatever" 
  else local rnames "`rnames' `:word `i' of `:rownames(a)''"
  }
 mat rownames a=`rnames'
 mat list a

(2) To save the first 2 rownames as a macro:

 mat a=(1,2\ 3,4\ 5,6)
 forv i=1/2 {
  local rnames "`rnames' `:word `i' of `:rownames(a)''"
  }
 di "`rnames'"

Note that the rownames *must not* contain spaces, since the extended
macro function -rownames()- returns the names without quotes.
Furthermore, only names will be changed but not eqnames (use the
extended macro function -fullrownames()- if you want to change both).

The resulting macro 'rnames' will have a leading space (usually, this is
irrelevant). If you want to remove it, type
 
 local rnames: list retokenize rnames

ben


> -----Original Message-----
> From: John D. Levendis [mailto:[email protected]] 
> Sent: Wednesday, September 03, 2003 10:18 PM
> To: statalist
> Subject: st: column and row naming
> 
> 
> Hello Statalisters,
> 
> I've got two related questions regarding column and row names.
> (1) How can I replace the 'jth' column name only?
> (2) How can I save as a macro the 1st j column names from a matrix?
> 
> Many thanks.
> 
> --John
> 
> 
> ----------------------------------------
> John D. Levendis
> W210 Pappajohn Bus. Bldg
> University of Iowa
> Iowa City, IA 52242
> ----------------------------------------
> 
> 
> *
> *   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/



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