Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Reshape question


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: Reshape question
Date   Mon, 14 Sep 2009 09:21:28 +0200

Am Montag, den 14.09.2009, 06:27 +0200 schrieb Si Yue Li:
> as a beginner, I am having some trouble importing large excel datatables 
> containing datastream output into stata long format. I checked with 
> faq/help files and think that the reshape command combined with some 
> data manipulations must be the answer. Right now I can get the data to 
> look like this in Stata:
> |v1|v2|v3|v4|v5|...    
> |.|ID code1|ID code2|ID code3|ID code4|...         
> |date1| Xij|Xij|Xij|Xij|...
> |date2| Xij|Xij|Xij|Xij|...
> |...|...|...|...|...
> 
> where Xij = Data
> 
> However from my past Stata experiences the usual long form is much 
> better to work with:
> 
> |ID code1|date1|Xij|
> |ID code1|date2|Xij|
> |...|...|...|
> |ID code2|date1|Xij|
> |ID code2|date2|Xij|
> |...|...|...|
> 
> I think reshape will solve this for me, but I couldn't get anything to 
> work...


Which command do you have used to read in your Excel file? I have
created the file foo.raw as tab separated values file. You get this
format by saving as "plain text (.tsv)" in Excel. The Stata command 

. cat foo.raw, showtabs

should produce something like this:

.<T>ID code1<T>ID code2<T>ID code3<T>ID code4
date1<T> 15<T>15<T>15<T>15
date2<T> 15<T>15<T>15<T>15
 
whereby <T> indicates a tab.  If I read in foo.raw with 

. insheet using foo.raw

I get

. l, clean

          v1   idcode1   idcode2   idcode3   idcode4  
  1.   date1        15        15        15        15  
  2.   date2        15        15        15        15  


which could be reshaped to long as follows

. reshape long idcode, i(v1)


Many regards
Uli

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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