[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: How to change matrix row names
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
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.
> -----Original Message-----
> From: email@example.com
> [mailto:firstname.lastname@example.org]On Behalf Of Friedrich
> Sent: 01 November 2004 17:56
> To: email@example.com
> 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
> 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: