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]
Re: st: How to create a blank n x n matrix; how to refer to variables without using ID; how to extract colnames and rownames from the dataset.
From
"Chen, Xianwen" <[email protected]>
To
[email protected]
Subject
Re: st: How to create a blank n x n matrix; how to refer to variables without using ID; how to extract colnames and rownames from the dataset.
Date
Wed, 9 Mar 2011 15:08:57 +0100
Thanks a lot Maaten! Problem solved!
Xianwen
On Wed, Mar 9, 2011 at 2:06 PM, Maarten buis <[email protected]> wrote:
>
> --- On Wed, 9/3/11, Chen, Xianwen wrote:
> > The first question is a fast way to create a n x n matrix.
> > For example, to create a 8 x 8 matrix for later data
> > manipulation.
>
> matrix foo = J(8,8,.)
>
> This creates a 8x8 matrix containing all missing values (.).
>
> > The second question is regarding variables. I want to
> > search through the variables by each entry of the data. I
> > can specify the column IDs but I want a more automated
> > solution.
> >
> > Is there a way of working with it, say somefunction{1,}
> > will actually refer to the first column of the dataset?
>
> In Stata you almost always work with variable names and not
> column numbers. It really really really pays to start learning
> that if you want to be an effective user of Stata.
>
> Having said that you can do it:
>
> ds
> local varl "`r(varlist)'"
>
> first variable (column) is called `: word 1 of `varl''
> second variable is called `: word 2 of `varl''
> etc.
>
> > The third question is to extract colnames and rownames from
> > the datasets. Is there a function I can use?
>
> column names are variable names in Stata. You can get that
> using -ds-
>
> rownames are just observation numbers, you can get those using
> _n
>
> It looks to me that you are comming from another package that
> works primary with matrices. Stata does not function that way,
> in the sense that it primarily works on a dataset with
> variables and observations instead of rows and columns. All
> functions are geared towards that structure. You can try to
> translate that to matrix manipulations, but then you will be
> making your live unnecesarily hard (and your computations
> unnecesarily slow) because Stata was just not designed for
> that purpose. If you do not want to change your habbits then
> your best bet would be to use Mata instead of Stata, because
> Mata is designed for dealing with matrices instead of dealing
> with data.
>
> Hope this helps,
> Maarten
>
> --------------------------
> Maarten L. Buis
> Institut fuer Soziologie
> Universitaet Tuebingen
> Wilhelmstrasse 36
> 72074 Tuebingen
> Germany
>
> http://www.maartenbuis.nl
> --------------------------
>
>
>
>
> *
> * 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/
*
* 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/