Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: How to insert the name of a variable into a matrix automatically


From   yaacov lawrence <yaacovla@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: How to insert the name of a variable into a matrix automatically
Date   Sun, 9 Sep 2012 18:58:37 +0300

For a medical epidemiological project looking at cancer incidence I
should like Stata to create a descriptive table of the variables as a
matrix that I will then export to Excel. There will be one row for
each variable. The various columns include number of observations,
median age, etc. I am using the "foreach" command.

All works well.
The only problem is that I should like the first cell of each row to
contain the variable name, and I cannot see how to do this. I realize
that I could do this manually using "matrix rownames" but I would
rather do it automatically.

example of the code below:

thank you!!

yaacov
-------------

matrix cancertypes = J(10,4,.)
matrix colnames cancertypes = "cancer_type" N median_age "%white"
local rownumber 1

foreach var of varlist head lowgi {
count if `var'==1
matrix cancertypes[`rownumber',2]=r(N)
summarize AGE if `var'==1, detail
matrix cancertypes[`rownumber',3]=r(p50)
local rownumber=`rownumber'+1
}

matrix list cancertypes



--

Dr Yaacov Richard Lawrence MBBS MA MRCP
Sheba Medical Center
Tel HaShomer 52621


yaacov.lawrence@sheba.health.gov.il
yaacovla@gmail.com
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index