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

st: RE: Re: retaining residuals using "by group" with regression


From   Roger Newson <[email protected]>
To   [email protected]
Subject   st: RE: Re: retaining residuals using "by group" with regression
Date   Tue, 27 Jan 2004 17:27:08 +0000

At 16:05 27/01/04 +0000, Nick Cox wrote:
I concur with the advice to start
with -levels-, but this seems a little
more complicated than it need be.

levels company, local(C)
gen zresid = .
qui foreach c of local C {
    regress y x1 x2 x3 if company == `c'
    predict temp, rstudent
    replace zresid = temp if company == `c'
    drop temp
}
save data_with_zresid

Good idea Nick. This should save a bit of file-processing time. (I must have been thinking in "SAS mode", which is only appropriate if the output data set has observations corresponding to something other than the observations of the original data set.)

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: [email protected]
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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index