Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Reshaping but not numeric and more a loop needed!


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: Reshaping but not numeric and more a loop needed!
Date   Sat, 29 Oct 2011 19:14:33 -0500

Something like this?

clear
input  A       B
1.11    1.11
1.11    1.12
1.11    1.13
1.11    1.14
1.11    1.15
1.11    1.16
1.11    1.19
1.11    1.26
1.11    1.28
1.11    1.29
1.11    1.63
1.11    1.64
1.20    1.11
1.20    1.12
1.20    1.20
1.20    1.20
1.21    1.13
1.21    1.14
1.21    1.21
1.21    1.22
1.21    1.23
end

bys A: gen tag = _n
egen tag2 = group(A)
reshape wide A B, j(tag) i(tag2)
rename A1 A
drop A? A?? tag2
l


Scott

On Sat, Oct 29, 2011 at 6:29 PM, Miyu Lee <[email protected]> wrote:
> Hello
>
> I want to reshape the following table
>
> A           B
> 1.11    1.11
> 1.11    1.12
> 1.11    1.13
> 1.11    1.14
> 1.11    1.15
> 1.11    1.16
> 1.11    1.19
> 1.11    1.26
> 1.11    1.28
> 1.11    1.29
> 1.11    1.63
> 1.11    1.64
> 1.20    1.11
> 1.20    1.12
> 1.20    1.20
> 1.20    1.20
> 1.21    1.13
> 1.21    1.14
> 1.21    1.21
> 1.21    1.22
> 1.21    1.23
> etc     etc
>
> to look like this:
>
> A          B1       B2     B3
> 1.11    1.11     1.12    1.13 etc
> 1.20    1.11     1.12    1.20 etc
> 1.21    1.14 etc.
>
> !!! my ideal would be if STATA just puts the B value next to the B
> value of the first observation within each group, as long as the A
> values are the same.!!!
>
> reshape does not work here because it creates a huge matrix where all
> identical B values are stacked on top of each other and/or there might
> also be a problem that the size of the group is not equal.
>
> any suggestions would be helpful. the matrix is very long so a loop or
> anything similar seems the only alternative.
>
> Many thanks
>
> Miyu
> *
> *   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/
>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index