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

RE: st: Ritesh's Inquiry (correction)


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Ritesh's Inquiry (correction)
Date   Sat, 5 Jul 2003 22:51:19 +0100

Sorry, I need to correct the code just posted: 

In Stata terms this is, with a group structure:
 
bysort group : gen newvar = sum(score)
by group : replace newvar = (newvar[_N] - score) / (_N - 1)
 
There could be at least one problem with
this, any missing values in -score-.
 
The extra wrinkle to cope with that is
something like
 
bysort group : gen newvar = sum(score)
by group : gen N = sum(score < .)
by group : replace newvar = (newvar[_N] - score) / (N[_N] - 1)

or like
 
bysort group : gen newvar = sum(score)
by group : egen N = count(score)
by group : replace newvar = (newvar[_N] - score) / (N - 1)

Nick
[email protected]

P.S. another way to do it 

bysort group : egen newvar = sum(score)
by group : egen N = count(score)
by group : replace newvar = (newvar - score) / (N - 1)

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