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

st: RE: How to change matrix row names


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: How to change matrix row names
Date   Mon, 1 Nov 2004 18:33:59 -0000

Sorry, but this sounds backwards to me, probably 
because I am not totally clear on your final goal. 

You are using one program to put stuff in a matrix and 
then other programs to take it out again and put it 
in variables. 

It's true that you are hitting a limitation of 
-matrix rownames- (which -svmat2- when written 
in 1999, and now, could do nothing about) but 
some direct way from a dataset to a resultsset 
e.g. -collapse-, -egen-, 
would seem preferable to going from New York 
to New Jersey via New Mexico. 

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Friedrich
> Huebler
> Sent: 01 November 2004 17:56
> To: [email protected]
> Subject: st: How to change matrix row names
> 
> 
> This is a followup to a question I posted on October 13. I found one
> solution with the help of Stata tech support but hope for additional
> advice from Statalist members. To make the problem clearer I include
> more information than in my original message.
> 
> I am looking for a way to save a matrix that was created with
> -tabstat, by()-. An important assumption is that the value labels of
> the -by- variable are not known in advance. I want to save the row
> names together with the matrix values but don't know what to do when
> the row names contain certain special characters like spaces or
> apostrophes.
> 
> Think of a national dataset with a variable "state"; we know the name
> of the variable and the name of the value label (e.g., "statename")
> but we don't know the individual labels (e.g., "New Jersey", "New
> Mexico" and so on). This case can be reproduced with the auto data.
> The following commands create a 3x1 matrix with row names that
> contain spaces. The matrix is then saved in two new variables called
> "table1" and "label". I use -tabstatmat- from SSC (-findit
> tabstatmat-) and -svmat2- from STB-56 (-findit svmat2-).
> 
> . sysuse auto, clear
> . lab def origin 0 "Domestic cars" 1 "Foreign cars", modify
> . tabstat mpg, by(foreign) save
> . tabstatmat table
> . svmat2 table, rnames(label)
> 
> I use -svmat2- because I don't know any other command that places
> matrix row names in a variable. The matrix has three rows with the
> names "Domestic cars", "Foreign cars", and "Total". -svmat2-
> interprets ever single word as a label so that the saved matrix looks
> as follows.
> 
> . clist label table1 if table1<., noobs
> 
>    label     table1
> Domestic   19.82692
>     cars   24.77273
>  Foreign    21.2973
> 
> My theoretical solution was to change the labels "Domestic cars" and
> "Foreign cars" to "Domestic_cars" and "Foreign_cars". I tried
> replacing all spaces with underscores but the following sequence of
> commands changes all row names to "Domestic_cars_Foreign_cars_Total".
> 
> 
> . local names: rowfullnames table
> . local names: subinstr local names " " "_", all
> . matrix rownames table = `names'
> 
> Can one of the matrix wizards on this list suggest a way to replace
> the spaces in the row names? In the end I hope to create two
> variables that look like this:
> 
>         label     table1
> Domestic_cars   19.82692
>  Foreign_cars   24.77273
>         Total    21.2973
> 
> Stata tech support provided one solution in which individual value
> labels are modified before the matrix is created. This solution
> requires saving the labels in a temporary file on the hard drive.
> During my exchange with tech support I was told that there are
> numerous ways to modify label names and very few that modify matrix
> row and column names. Therefore it was recommended to tackle the
> problem upstream. Nevertheless, I think that manipulating the
> -tabstat- matrix, if possible, would be more efficient because it
> should not require hard drive access.
> 

*
*   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