Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: xpose or reshape


From   "Wallace, John" <[email protected]>
To   <[email protected]>
Subject   st: xpose or reshape
Date   Mon, 11 Oct 2004 17:32:31 -0700

Hi Statalisters
I've come across what appears to be a simple transposition problem, but I'm unable to solve it.  I have a tab-delimited text-file data source where the records are columns and the variables are rows.  The variable labels are effectively the first column, and the record labels are the first row, thus:

	v1	v2		v3		v4		v5
1		foo1.chp	foo2.chp	foo3.chp	foo4.chp
2	Date	10/11/04	10/11/04	10/11/04	10/11/04
3	type	U133A_2	U133A_2	U133A_2	U133A_2
4	group	lymph		lymph		lymph		heart
5	noise	1.4		1.24		1.5		1.25
6	bkd	46.7		50.4		32.4		18.6
7	bkdsd	.28		.28		.26		.09

It looks like a clear case for -xpose-, except that all the data are brought into Stata as strings because the first row (filenames) are strings.  -xpose- results in an empty dataset.  I'm looking at reshape and stack, but I can't figure out how they could accomplish what I'm looking for:

	v1	v2		v3		v4		v5	v6	v7	v8
1	v1	.		Date		type		group	noise	bkd	bkdsd
2	v2	foo1.chp	10/11/2004	U133A_2	lymph	1.4	46.7	0.28
3	v3	foo2.chp	10/11/2004	U133A_2	lymph	1.24	50.4	0.28
4	v4	foo3.chp	10/11/2004	U133A_2	lymph	1.5	32.4	0.26
5	v5	foo4.chp	10/11/2004	U133A_2	heart	1.25	18.6	0.09

(or actually, ideally)

	v1		Date		type		group	noise	bkd	bkdsd
1	foo1.chp	10/11/2004	U133A_2	lymph	1.4	46.7	0.28
2	foo2.chp	10/11/2004	U133A_2	lymph	1.24	50.4	0.28
3	foo3.chp	10/11/2004	U133A_2	lymph	1.5	32.4	0.26
4	foo4.chp	10/11/2004	U133A_2	heart	1.25	18.6	0.09

Previously, I've handled similar problems by resorting to Excel - importing the text file, using the copy/Paste Special ..transpose function, then exporting the result as a text file and proceeding with Stata.  My trick has failed me though, this time I have more than 256 records!  (Excel can't handle anything wider than 256, or longer than 65535 for that matter).

John Wallace�|�Research Associate�| Test Method Development
AFFYMETRIX, INC. | 3380 Central Expressway | Santa Clara, CA 95051 | Tel:� 408-731-5574 | Fax:� 408-481-0435


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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index