Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[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 <[email protected]>
To   [email protected]
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


[email protected]
[email protected]
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index