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

st: RE: Collapsing records


From   [email protected]
To   [email protected]
Subject   st: RE: Collapsing records
Date   Fri, 21 Feb 2003 13:19:51 -0500

Eric G. Wruck
> I have student rosters for a school over many years.  Not 
> surprisingly, siblings often go to the same school.  I want 
> to go from student-level records to a family record.
> 
> An example of what I currently have is:
> 
> 
>            last       first    id   fam_id   yrs  
> 116.    Carlson     Finnian    40       92     9  
> 117.    Carlson        Liam    41       92    10  
> 544.    Petroff   Alexander   654      420     3  
> 545.    Petroff     Allison   589      420     4  
> 546.    Petroff        Kate   590      420     4  
> 
> What I would like is something like:
> 
> fam_id	last1	first1 		id1	yrs1	last2 	
> first2	id2	yrs2	etc.
> 92	Carlson	Finnian		40	9	Carlson	Liam	
> 41	10
> 420	Petroff	Alexander	654	3	Petroff	Allison	
> 589	4
> 
> 
> I played around with -reshape wide- unsuccessfully.  I 
> created a variable for the i() parameter which was simply an 
> index ranging from 1 to the number of kids in the family, but 
> couldn't figure out what j() should be.  

How about

   bysort fam_id : g byte kid = _n
   reshape wide last first id yrs, i(fam_id) j(kid)


Patrick Joly
[email protected]
[email protected]
*
*   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