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: Assigning values to a number of rows of a matrix
From
Eilya Torshizian <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: Assigning values to a number of rows of a matrix
Date
Mon, 24 Feb 2014 05:14:17 +0000
Dear Statalisters,
In a loop, I would like to add values derived from a command (such as -mean-) to a matrix. Let's assume GENDER and MARITAL are categorical variables with 2 categories, which brings the total categories to 4 (CAT=4). I need to create a matrix with the size of the number of categories. However, I could not derive the total number of unique values by using -inspect-.
*HOW TO DERIVE THE TOTAL UNIQUE VALUES FOR A VARLIST: global VARS GENDER MARITAL?
matrix M = J(`CAT',2,0)
local i = 1
foreach VAR of varlist GENDER MARITAL {
xi: mean i.`VAR'
local MEAN = e(b)
*HERE I DO NOT KNOW HOW TO SAY: MATRIX M[1:2,1] = MEAN[1:2,1]:
matrix M[`i',1] = MEAN
local i = `i' + `THE NUMBER OF CATEGORIES OF `VAR'' - 1
}
In the end, I would like to save the M matrix as an 'rtf' document.
Thanks,
Eilya.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/