# Re: st: Mata & Graphs

 From "Raphael Fraser" To statalist@hsphsun2.harvard.edu Subject Re: st: Mata & Graphs Date Tue, 25 Jul 2006 18:44:27 -0500

```Thanks Ben. I think I have solved the problem.

mata
st_matrix("tmpQ", Q) /*set the contents of tmpQ to be Q*/
stata("svmat tmpQ, names(x)") /*stores the columns of tmpQ as new
variables x1 and x2*/
st_matrix("tmpQ", J(0, 0, .)) /*deletes the matrix tmpQ*/
stata("twoway line x1 x2")
end

On 7/25/06, Ben  Jann <ben.jann@soz.gess.ethz.ch> wrote:
```
```Raphael wrote:
> I have the following matrix X, in Mata and would like to
> draw a twoway line graph using each column as a variable.
> How is this done?
>
>              1             2
>   +-----------------------------+
> 1 |  .8913041862             1  |
> 2 |  .8708690808             2  |
> 3 |  .8413558121             3  |
>   +-----------------------------+

Here is my solution:

mata:
void plot(
real colvector y,
real colvector x,
| string scalar opts)
{
real scalar n, N, Y, X

n = rows(y)
if (rows(x)!=n) _error(3200)
N = st_nobs()
stata("twoway scatter " + st_varname(Y) + " " +
st_varname(X) + ", " + opts)
if (N<n) st_dropobsin((N+1,n))
st_dropvar((Y,X))
}
end

mata: y = .8913041862 \ .8708690808 \ .8413558121
mata: x = 1 \ 2 \ 3
mata: plot(y, x)
mata: plot(y, x, "c(l)")

ben

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

```
```*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```