Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: reshape


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: reshape
Date   Mon, 4 Jun 2012 11:51:50 +0100

You don't show your code so I can't comment on what you are doing
wrong. At a wild guess you are trying to do this with one -reshape-,
but I see it as a long - long reshape, so you need two.

See the appropriate sections in

FAQ     . . . . . . . . . . . . . . . . . . . . . . . .  Problems with reshape
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        12/03   I am having problems with the reshape command. Can
                you give further guidance?
                http://www.stata.com/support/faqs/data/reshape3.html

Code something like this. (If you have Stata 12 or have installed
-renvars- (SJ), the initial renaming can be simpler.)

foreach v of var pov* {
	local newname : subinstr local v "_def" ""
	rename `v' `newname'
}

reshape long povcl1 povcl2 povcl3 , i(region) j(def)

reshape long povcl , i(region def)
rename povcl rate
rename _j povcl


On Mon, Jun 4, 2012 at 11:06 AM, Ronnie Babigumira <rb.glists@gmail.com> wrote:

> I have what I think qualifies as a knotty data management problem. Not having much success so hoping someone can help.
>
> some data
>
> region povcl1_def2 povcl1_def1 povcl2_def2 povcl2_def1 povcl3_def2 povcl3_def1
> 1 7.9 32.6 4.1 12.8 15.3 27.2
>
> 2 2.2 3.1 3.1 5.2 45.1 41.2
>
> this is where I would like to go
> region povcl def rate
> 1 1 2 7.9
> 1 1 1 32.6
> 1 2 2 4.1
> 1 2 1 12.8
> 1 3 2 15.3
> 1 3 1 27.2
> .....
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index