Dear List Members,
I am looking for a flexible way to create matrices from -tabstat-
output that does not require previous knowledge of the number of rows
in the table. Let's take a household survey dataset with some
indicator and make a table for a subsample of persons aged 20-22
years.
. tabstat yes no if age>=20 & age<=22, by(age) save
age | yes no
----+--------------------
20 | 60 40
21 | 50 50
22 | 55 45
----+--------------------
Tot | 52 48
-------------------------
. return list
macros:
r(name3) : "22"
r(name2) : "21"
r(name1) : "20"
matrices:
r(Stat3) : 1 x 2
r(Stat2) : 1 x 2
r(Stat1) : 1 x 2
r(StatTot) : 1 x 2
Now I create a matrix. Note that I have to spell out the names of the
macros and matrices saved by -tabstat-.
. matrix sample1 = (r(Stat1) \ r(Stat2) \ r(Stat3) \ r(StatTot))
. matrix rownames sample1 = `r(name1)' `r(name2)' `r(name3)' Total
. matrix list sample1
sample1[4,2]
yes no
20 60 40
21 50 50
22 55 45
Total 52 48
Are there alternatives to the commands that create the matrix and
assign row names? There should be commands that do not require
spelling out "r(Stat1) ..." and "`r(name1)' ..." These alternative
commands should work for -tabstat- tables of different lengths, for
example for persons aged 20-29 or 15-64 years.
Thank you for your help.
Friedrich Huebler
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
*
* 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/