Statalist


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

SV: st: join duplicated records from one datafile


From   "Bernhard Hansen" <[email protected]>
To   <[email protected]>
Subject   SV: st: join duplicated records from one datafile
Date   Mon, 25 Feb 2008 11:31:17 +0100

Thanks a lot, it works

B. Hansen


-----Oprindelig meddelelse-----
Fra: [email protected] [mailto:[email protected]] P� vegne af Maarten buis
Sendt: 19. februar 2008 13:34
Til: [email protected]
Emne: Re: st: join duplicated records from one datafile

--- Bernhard Hansen <[email protected]> wrote:
> I have a data file with 2 variables and duplicates on one of these 
> like:
> 
> id  var1
> 
> 1    3
> 1    4
> 1    5
> 2    2
> 3    2
> 4    5
> 
> Now I want to turn each id into one unique record, and turning the
> information on var 1 into a range of new variables so that 
> I would like to end up with a data file looking like: 
> 
> id var1 var2 var 3
> 1  3     4     5 
> 2  2     .     .
> 3  2     .     .
> 4  5     .     .

This is a job for -reshape-, see -help reshape- and the example below:

*-------- begin example ------------
drop _all
input id  var1
1    3
1    4
1    5
2    2
3    2
4    5
end

bys id : gen t = _n
reshape wide var1, i(id) j(t)
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/
-----------------------------------------


      ___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.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/

*
*   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