# st: How can we extract matrices from STATA data

 From "Nadeem Shafique" To statalist@hsphsun2.harvard.edu Subject st: How can we extract matrices from STATA data Date Fri, 17 Aug 2007 16:51:16 +0500

```Respected All,

I have entered data into stata data editor and i wish to extract
matrices from the data set and want to

write STATA Mata function for further maipulations. For example
consider the following data
m	v1	v2 	v3	gr
23	1	2	3	1
11	3	1	2	1
23	2	2	1	1
25	1	2	3	2
23	2	1	2	2
28	3	3	1	2
2	1	1	2	3
3	1	3	1	3
1	2	1	2	3
.	.	.	.	4
.	.	.	.	4
.	.	.	.	4

i wish to extract

m1=(23,11,23) m2=(25,23,28) and m3=(2,3,1)

var1=(1,2,3/3,1,2/2,2,1) var2=(1,2,3/2,1,2/3,3,1) and v3=(1,1,2/1,3,1/2,1,2)

Can we make a general program that can extract matrices and vectors
based on the grouping variable

entered in stata data editor.

Further if a code is repeated 4 times in grouping variable will
implies that there will be four enteries

in "m" vectors and "var" matrices will be of order 4 X 4 and so on.

Looking for the solution to this problem. If anyone can help me I will
be highly thankful.

Regards,