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

st: Save matrix with long row names

From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   st: Save matrix with long row names
Date   Wed, 13 Oct 2004 17:12:48 -0700 (PDT)

I am looking for a way to save a matrix with long row names. Usually
I use -svmat2- from STB-56 for this purpose but if a row name
contains spaces, -svmat2- interprets every single word as a row name.

. sysuse auto, clear
. lab def origin 0 "Domestic cars" 1 "Foreign cars", modify
. tabstat mpg, by(foreign) save
. tabstatmat table
. svmat2 table, rnames(label)
. clist label table1 if table1<., noobs

   label     table1
Domestic   19.82692
    cars   24.77273
 Foreign    21.2973

In theory, the problem can be solved in two ways: (a) modify the
value labels by changing all spaces to a different character, or (b)
modify the row names of the matrix. Both solutions have to work in
cases when the value labels are unknown. I tried the second approach
but don't get what I need.

. matrix list table

Domestic cars  19.826923
 Foreign cars  24.772727
        Total  21.297297

. local names: rowfullnames table
. local names: subinstr local names " " "_", all
. matrix rownames table = `names'
. matrix list table

Domestic_cars_Foreign_cars_Total  19.826923
Domestic_cars_Foreign_cars_Total  24.772727
Domestic_cars_Foreign_cars_Total  21.297297

If you know of a way to remove spaces from value labels or matrix row
names please share your solution with the list.

Thank you,

Friedrich Huebler


*   For searches and help try:

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