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

Re: st: Reshape or other approach for multiple-response data


From   Roger Newson <[email protected]>
To   [email protected]
Subject   Re: st: Reshape or other approach for multiple-response data
Date   Wed, 13 Apr 2005 20:39:34 +0100

At 18:54 13/04/2005, Arnold H. Levinson wrote:
Friends,
I have a long dataset with variables that allow multiple responses per
subject. So it looks like:

ID    var1    var2
1        3        5
1        2        .
2        3        4
2        .        5
etc.
Reshape doesn't like multiple responses for a single variable. What's the
most efficient way of reshaping to wide, with each variable becoming a
response-specific dummy, i.e., var1_1, var1_2, etc.
I think the first step is to define a second variable, containing the response sequence of the observation within its ID. If Arnold types

sort ID, stable
by ID: gene long respseq=_n
compress respseq
lab var respseq "Response sequence within ID"
sort ID respseq

then Arnold will have a dataset sorted by -ID- and -respseq-, with 1 observation with each combination of -ID- and -respseq-. If Arnold then types

foreach X of var var* {
rename `X' `X'_
}
reshape wide var*, i(ID) j(respseq)

then the resulting dataset should contain variables var1_1, var1_2 etc. and var2_1, var2_2 etc.

I hope this helps.

Roger



--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
Division of Asthma, Allergy and Lung Biology
King's College London

5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]
Website: http://phs.kcl.ac.uk/rogernewson/

Opinions expressed are those of the author, not the institution.

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