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

st: RE: A tricky reshape


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: A tricky reshape
Date   Fri, 25 Jun 2004 12:53:17 +0100

I am not surprised that the stock
commands don't work. Your data don't 
yet satisfy the criteria for a -reshape-. 

A similar problem is discussed at 
http://www.stata.com/support/faqs/data/reshape3.html
In essence, you need a mass re-naming. 

So long as you are using stubs 
Jan Feb Mar Apr May Jun Jul Aug Sep 
Oct Nov Dec, try this: 

di "`c(Mons)'"
tokenize `c(Mons)' 
forval i = 1/12 { 
	forval j = 1/7 { 
		rename ``m''X`j'  X`j'`m' 
	}
}
gen i = _n 
reshape long X1 X2 X3 X4 X5 X6 X7, j(month) i(i) 

Nick 
[email protected] 

Hawken, Angela
> 
> I'm struggling to reshape a dataset.  I need to go from wide 
> to long.  The
> format is:
> 
> State JanX1 JanX2...JanX7...DecX6 DecX7
> State is a unique identifier.
> 
> I need it in the form:
> State Month X1...X7
> 
> This seemed simple when I started but the stock commands 
> don't seem to work.

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