[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: xpose or reshape |

Date |
Tue, 12 Oct 2004 11:10:38 +0100 |

In this case, I would go back a step and read in the data using -infile, byvariable()-. For your example set, you need 7 string variables, and 5 observations, and there are no blanks within strings, so try forval i = 1/7 { local args "`args' str80 v`i'" } infile `args' using <whateverfile>, byvariable(5) foreach v of var * { capture rename `v' `=`v'[1]' } drop in 1 compress > 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 Nick n.j.cox@durham.ac.uk Wallace, John > 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). > * * 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/

- Prev by Date:
**st: RE: clonevar** - Next by Date:
**st: Time variable not regularly spaced** - Previous by thread:
**st: RE: clonevar** - Next by thread:
**st: RE: xpose or reshape** - Index(es):

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