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

Re: st: Elementary question

From   "Urara Hiroeh" <>
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

. 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
Manchester  M14 6ZT

Home: +44 0161 225 4129
Work: +44 0161 291 4843 (fax 4358)

*   For searches and help try:

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