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 command with multiple variables


From   Steve Nakoneshny <scnakone@ucalgary.ca>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: reshape command with multiple variables
Date   Sat, 17 Nov 2012 16:25:51 -0700

-reshape- is working as intended. Your problem can be solved with a judicious use of -order-. At a glance, I would guess that -order personid a* b* c*- will arrange your vars as desired.

Steve

Sent via carrier pigeon

On 2012-11-17, at 3:28 PM, "Whitney Cox" <wcox@parchment.com> wrote:

> I have a date set that contains the following:
> 
> Persionid    A    B    C    period
> 123        5    6    7    2012-01
> 123        7    5    2    2012-02    
> 123        6    3    4    2012-03
> 123        7    3    6    2012-04
> 123        8    4    7    2012-05
> 213        6    6    9    2012-01
> 213        3    3    5    2012-02
> 213        4    8    7    2012-04
> 312        7    5    6    2012-01
> 312        8    3    4    2012-02
> 312        9    4    8    2012-03
> 
> The command:       reshape wide a b c , i(personid) j(period) string
> 
> Gives me the data with the grouping of A, B, C repeated as a group from
> each row for each of the periods across the row as follows:
> 
> Personid    A2012-01    B2012-01    C2012-01    A2012-02
> B2012-02    C2012-02    A2012-03    B2012-03    C2012-03
> A2012-04    B2012-043    C2012-04    A2012-05    B2012-05
> CE2012-05    
> 
> 123            5        6        7        7
> 5        2        6        3        4
> 7        3        6        8        5
> 7    
> 213            6        6        9        3
> 3        5
> 4        8        7
> 312            7        5        6        8
> 3        4        9        4        8
> 
> What I real want is all the As from across the time range, then all the Bs
> then all the Cs , as shown below:
> 
> 
> Personid    A2012-01    A2012-02    A2012-03    A2012-04
> A2012-05    B2012-01    B2012-02    B2012-03    B2012-04
> B2012-05    C2012-01    C2012-02    C2012-03    C2012-04
> C2012-05
> 
> 123            5        7        6        7
> 8        6        5        3        3
> 4        7        2        4        6
> 7
> 213            6        3                4
> 6        3                8
> 9        5                7
> 312            7        8        9
> 5        3        4
> 6        4        8    
> 
> How do I word the reshape command to give me the format above, where all
> of the A columns are first, then the B columns, then the C columns  ?
> 
> Thanks
> 
> Whit
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index