Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: reorganize data


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: reorganize data
Date   Mon, 31 Dec 2007 13:29:39 +0000 (GMT)

--- DerSpiderman27@aol.com wrote:
[I changed the tables for readability]
> My data is organized as follows... for example:
> 
> id        byr
> 2         1973
> 2         1975
> 3         1954
> 4         1965
> 4         1967
> 4         1969
> 
> My problem is,  that the identifyers appear more than once. I want to
> restructure the data to  get it into the
> form:
> 
> id     byr1    byr2    byr3
> 2      1973    1975    .
> 3      1954    .       .
> 4      1965    1967    1969

-reshape- is your friend here. See the example below:

*----------- begin example ----------------
clear
input long id     byr
2         1973
2         1975
3         1954
4         1965
4         1967
4        1969
end
label variable byr "birth year of child"

sort id byr
by id : gen bord = _n
label variable bord "birth order"
/*what to do with when two siblings are born*/
/*in the same year, e.g. twins?*/

reshape wide byr, i(id) j(bord)
list
*--------------- end example ------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      __________________________________________________________
Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com

*
*   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–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index