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

st: RE: putting value label categories into a matrix

From   "Milly Marston" <[email protected]>
To   <[email protected]>
Subject   st: RE: putting value label categories into a matrix
Date   Mon, 10 Dec 2007 13:53:24 +0000

Thanks Nick,

Actually I am attempting strategy 1.  I have a very large amount of
data on different countries with similar data, but some with missing
categories.   If I can automate my tables in Stata first it saves time
and also mistakes cutting and pasting.  

I am trying to produce a table in Stata that first has the variable
categories (labelled) and then next to each category in columns various
statistics I would like picked from different return codes.  I will then
use file write to export the final table.

The reason I would like the matrix of data labels and values is so that
for each variable I can identify how many categories there should be.  
Each country might have a missing category so if I wish them to line up
at the end I want to make sure that where the category is missing I
include a line blank with no statistics rather than having a shorter
table that will not line up with others.    Having the labels and their
values in a matrix would make the identifying which label equates to
which value easier than creating local macros from equal points from two
different macro lists (labels and values).   Conclusion, I think perhaps
now's the time to delve into the world of Mata...

Estout is a great friend of mine! It is very useful.    Out of interest
is there a reason why there isn't an option to put the actual data
labels in the output (regression commands and estout) rather than the
variable name with it's category number?   ... perhaps that is for
another thread


>>> "Nick Cox" <[email protected]> 10/12/2007 09:32 >>>
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
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
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
reply very promptly. 

[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

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

I see that there is something in Mata using "st_vlmap" but
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
able to vary so I can put all my variables through the command without
listing each number corresponding to the value label

sexlabels=st_vlmap("sex", (1,2))
display a

Why am I doing this? -  to save time so I can output my repeated
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
to avoid running with Mata before I can walk!

*   For searches and help try:
*   For searches and help try:

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