Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: putting value label categories into a matrix


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: putting value label categories into a matrix
Date   Mon, 10 Dec 2007 09:32:10 -0000

You are in a bind here. If you want to put string values 
_into_ a matrix, you must use Mata, as Stata's matrices
will not hold strings. You may use string values as 
labels for Stata matrices' rows and columns, but that's 
quite different. 

In any case, what you seem to want to do does not appear an 
especially good idea to me. You seem to be working backwards
from the need to present tables, quite possibly in some other 
(unspecified) software. This is a very common desire among Stata users, 
but no one can agree on a single best solution. There 
are various routes that people prefer, depending partly 
on what other software they intend to use. 

Strategies include: 

1. production of tables within Stata in a form more congenial than
Stata's standard outputs. 

2. production of results and/or tables by Stata as files readable by 
other programs, most commonly with a view to later use of one of various
flavours of *TeX, or MS Word, or MS Excel. 

Popular solutions include -estout- (Ben Jann), -outreg2- (Roy Wada), 
-outreg- (John Gallup), -xml_tab- (Michael Lokshin, Zurab Sajaia), 
-parmest- etc. (Roger Newson). 

What I think you have in mind has more disadvantages and fewer
advantages
than any of these. 

A -findit- on the program names will indicate locations. If you come
back to the list with specific questions, the various program authors
usually 
reply very promptly. 

Nick
[email protected] 

Milly Marston wrote 

I would like to get the value label categories of my variables into
matrices so for a simple example

For sex labelled 1=male and 2=female:

1              2
male        female

Where the first row is the values and the second the labels (or
transposed)

Is there anyway of doing this?  Even extracting the value labels to be
made into a list of strings in a macro would help.  eg  "male female"
similar to what the extended macro functions do for variable label, or
a return code in the label list command to capture the list in a matrix.


I see that there is something in Mata using "st_vlmap" but unfortunately
I am unfamiliar with Mata at the moment and have only been able to
extract a scalar from the matrix to be used in Stata using "st_local" .
Also with st_vlmap you seem to have to explicitly write down all the
values labels you would like in the matrix whereas I would need it to be
able to vary so I can put all my variables through the command without
listing each number corresponding to the value label

mata
sexlabels=st_vlmap("sex", (1,2))
a=sexlabels[1,1]
st_local(a)
end
display a

Why am I doing this? -  to save time so I can output my repeated results
in a form as close to the tables I want for presentation as possible.

I am not sure if I am missing something very simple, I appear to be
going round and round in circles on this one, and if possible would like
to avoid running with Mata before I can walk!


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