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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Reshape like problem |

Date |
Fri, 5 Jun 2009 12:53:34 +0100 |

This isn't a reshape-like problem in my book, as no overall change to data structure or shape is needed: you just want new identifier variables. In the example -id- was just equivalent to observation number. In that circumstance gen ID_1 = ceil(_n/3) is an alternative, as are egen id__1 = seq(), block(3) egen id__2 = seq(), to(3) The first is easy to think about: you are just rounding up 1/3, 2/3, 3/3, 4/3, ... to the next integer. The second two are just wrappers for trickery with -mod()- and -int()-. (I think -egen, seq()- predates -ceil()-.) Nick n.j.cox@durham.ac.uk Austin Nichols Pancho Villa <panchovillainnyc@gmail.com> : clear input id value 1 15 2 14 3 22 4 31 5 12 6 10 end g id_1=(id-mod(id-1,3)-1)/3+1 g id_2=mod(id-1,3)+1 l On Thu, Jun 4, 2009 at 2:15 PM, Pancho Villa <panchovillainnyc@gmail.com> wrote: > I have my data in this kind of form: > > id value > 1 15 > 2 14 > 3 22 > 4 31 > 5 12 > 6 10 > > id_1 id_2 value > 1 1 15 > 1 2 14 > 1 3 22 > 2 1 31 > 2 2 12 > 2 3 10 > > In other words, my data is stacked and would like to un-stack it. (I > can do reshape, I think. But this seems like a necessary first step.) > > Now, in my example, my id goes from 1 to 6, while I'd like id_1 to go > from 1 to 2 and id_2 from 1 to 3. In reality, my id goes from 1 to > 5084280, while I want id_1 to go from 1 to 2088 and id_2 from 1 to > 2435. (If you check, 2088 x 2435 = 5084280.) > > I'll really appreciate if you can share code addressing a very similar > problem so I can just paste it in my do file and tweak a few things. * * 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/

**Follow-Ups**:**Re: st: Reshape like problem***From:*Pancho Villa <panchovillainnyc@gmail.com>

**References**:**st: Reshape like problem***From:*Pancho Villa <panchovillainnyc@gmail.com>

**Re: st: Reshape like problem***From:*Austin Nichols <austinnichols@gmail.com>

- Prev by Date:
**st: Re: How can I loop a FOR command across columns of a matrix** - Next by Date:
**st: RE: appling string functions across observations** - Previous by thread:
**Re: st: Reshape like problem** - Next by thread:
**Re: st: Reshape like problem** - Index(es):

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