Dear Statalists,
I have a large set of labelled variables and I would like to use these labels as the rownames of a matrix. Importantly, the labels consist of several words, which is causing a problem with my present solution.
What I have so far is the following:
sysuse auto, clear
local rows
foreach var of varlist m* {
local labels: variable label `var'
local rows `rows' `labels'
}
mat A=J(5,1,.)
mat rownames A = `rows'
mat list A
In fact, I do almost get what I want. However, the problem is that each single word of a multi-word label is treated as a single row . This is why I get:
Make .
and .
Model .
Mileage .
(mpg) .
Instead, the result should look more like:
Make and Model .
Milage (mpg) .
... .
... .
... .
Unfortunately, my attempts of tying labels togther using e.g. "string()" or compound double quotes have been unsuccesful.
Therefore, I am grateful for any piece of advice on how to solve this seemingly simple problem.
I have a large set of labelled variables and I would like to use these labels as the rownames of a matrix. Importantly, the labels consist of several words, which is causing a problem with my present solution.
What I have so far is the following:
sysuse auto, clear
local rows
foreach var of varlist m* {
local labels: variable label `var'
local rows `rows' `labels'
}
mat A=J(5,1,.)
mat rownames A = `rows'
mat list A
In fact, I do almost get what I want. However, the problem is that each single word of a multi-word label is treated as a single row . This is why I get:
Make .
and .
Model .
Mileage .
(mpg) .
Instead, the result should look more like:
Make and Model .
Milage (mpg) .
... .
... .
... .
Unfortunately, my attempts of tying labels togther using e.g. "string()" or compound double quotes have been unsuccesful.
Therefore, I am grateful for any piece of advice on how to solve this seemingly simple problem.
Comment