Statalist


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

st: newbie request for advice regarding matrix


From   "Jacob Wegelin" <[email protected]>
To   [email protected]
Subject   st: newbie request for advice regarding matrix
Date   Mon, 12 Jan 2009 12:30:06 -0500

Can one easily plot two columns of a Stata matrix against each other?

Details of this question:

In Stata, we can only have one dataset "open" at a time. Yet it is
possible to have several matrices available at the same time.

Suppose I have a matrix like the following:

. matrix A = (2,1\3,2\-2,2)

. matrix list A

A[3,2]
    c1  c2
r1   2   1
r2   3   2
r3  -2   2

and I'd like to create, say, a scatterplot of c2 vs c1.

One approach is to save the current data temporarily, turn the matrix
into a dataset, and use the familiar twoway command:

. save tmp, replace
file tmp.dta saved

. clear

. svmat A , names(col)
number of observations will be reset to 3
Press any key to continue, or Break to abort
obs was 0, now 3

. list

     +---------+
     | c1   c2 |
     |---------|
  1. |  2    1 |
  2. |  3    2 |
  3. | -2    2 |
     +---------+

. twoway (scatter c2 c1)


But is there a way to approach it using just the matrix, without
disturbing the dataset in memory?

More generally, where should I look to educate myself on this kind of
stuff? Would the best information be found in the mata manual, or ...?

Bigger picture: Stata compares favorably with R (www.r-project.org) in
several ways. It tends to be more user-friendly, and certain tools
frequently used in conventional data analysis, such as
cross-tabulation, are standard in Stata, unlike in R. Thus one can
document one's data analysis with less ambiguity; -tabulate- means
-tabulate- because the function was not pulled from some private
researcher's library.

On the other hand, in R the number of matrices that one can hold in
memory and manipulate in the same session is limited only by the
memory of one's computer. Also, in R one can hold several *data
frames* in memory. A data frame is more like a Stata dataset than a
Stata matrix; its columns can be of any type (e.g., string,
qualitative, numeric).  If it were possible to manipulate matrices in
Stata, then Stata would compete with R in this area. Stata would be
especially competitive if matrices in Stata were generalized to allow
the columns of any matrix to be of arbitrary types--e.g., an "ID"
column which is str10, an "Age" column which is integer, etc.

Thanks for any pointers, including where I should be reading or what
Stata course I should sign up for

Jacob Wegelin
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index