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

Re: st: new: collapse2


From   Roger Newson <roger.newson@kcl.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: new: collapse2
Date   Wed, 04 Aug 2004 16:50:14 +0100

At 16:19 04/08/2004, Dan Blanchette wrote:
How about adding an option to save id variables during the -collapse-?
It would be great if you could do this:

. collapse2 (sum) grams kcal fat , by(personid) id(age gender sampwt stratum psu)

because age, gender etc do not vary within a person's set of observations.

I've been cheating -collapse- to get the same result by doing:

. collapse (sum) grams kcal fat , by(age gender sampwt stratum psu personid)
"Cheating" is probably the way to go, rather than adding a superfluous id() option. However, I would have typed:

. collapse (sum) grams kcal fat, by(personid age gender samput stratum psu)
. by personid: assert _N==1

That way, I would know that age, gender, samput, stratum and psu really are id variables for personid (because otherwise Stata would complain and stop).

Roger


--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
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: roger.newson@kcl.ac.uk
Website: http://www.kcl-phs.org.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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index