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: variable names in matrix


From   Stefan Pichler <[email protected]>
To   <[email protected]>
Subject   st: variable names in matrix
Date   Mon, 9 May 2011 20:54:55 +0200

Hello Stata list users,

my probelm is as follows, I have a dataset and want to save each
variable name and the sum of its observations into a matrix.

Short example:

dataset:

t7 t3 t4 .... (varnames)#

1  1  30 .... (values)
1  2   1 ....
1  3   5



should return a matrix "A" with:
A=
7 3
3 6
4 36

where in the first column I have the shortened variable name without
the "t" and in the second column the respective sum.

I tried til now:

mat A=J(1,2,.)
ds
foreach var in `r(varlist)' {

scalar aaa=sum(`var')

mat A=(A \ ??? , aaa)
}

The problem is how to get the varname in column 1, since the matrix
won't accept the string directly I would also be happy to get just the
number as identifier, as in the example.
Thanks for your help

Stefan


 		 	   		  
*
*   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