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

Re: st: Elementary question


From   "Urara Hiroeh" <urara.hiroeh@man.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Elementary question
Date   Fri, 06 Dec 2002 09:13:22 -0000

> I have a 22,000 row x 50 column flat datasheet (Excel format) that I'd
> like to "transpose" so that rows become columns and vice versa.  Excel
> clearly can't do it, and I'm certain that it would be simple to do it
> in stata - but I can't find an appropriate command.  I thought
> -reshape- would be the one, but the syntax for it seems more complex
> than would be necessary. Note-I already saved it as a tab-delimited
> text file and imported it using -insheet-.

I had to do a similar thing and -reshape- worked for me - it depends on 
what kind of data you have, and what you want to do.  

My dataset had one patient per each row with dates of episodes recorded 
horizontally.  I wanted to switch that to a episode per every row format.  
The great thing about -reshape- is that it lets you identify the repeated 
variables (in my case episode variables e1 e2....e30) and it changes it to 
a column called episode in my case with numbers 1-30 indicating which 
episode the row is indicating.  

For example, 

Data Before:
id	e1		e2		e3
1	01jan1995	01mar1998	10nov1999

run:
. reshape long e, i(id) j(episode)
(note:  j = 1 2 3)

Data                               wide   ->  long
---------------------------------------------------------------------------
--
Number of obs.                        1   ->       3
Number of variables                   4   ->       3
j variable (3 values)                     ->   episode
xij variables:
                               e1 e2 e3   ->   e
---------------------------------------------------------------------------

Data After:
id	episode	e	
1	1		01jan1995
1	2		01mar1998
1	3		10nov1999



On the other hand, if you're just looking to straightforwardly switch rows 
and columns, then -xpose- is probably easier.

Urara Hiroeh

***
Urara Hiroeh
5 Lowry House
Opal Court
Moseley Road
Fallowfield
Manchester  M14 6ZT

Home: +44 0161 225 4129
Work: +44 0161 291 4843 (fax 4358)
Urara@fs1.with.man.ac.uk
UHiroeh@netscape.net

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index