--- [email protected] wrote:
> I'm trying to create a variable that is the stepwise, by group,
> cummulative tally of another variables values. For example, say I
> have three groups of different size, where all members of the group
> have the same score. My goal is to add the score from the current
> group to the preceeding group, on down, so the final group's
> calculated value is the sum of all groups scores.
*--------- begin example ------------
drop _all
input groupid score
1 5
1 5
2 11
2 11
3 4
3 4
3 4
3 4
end
bys groupid: gen byte first = _n == 1
bys first groupid: gen newvar = sum(score) if first
replace first = -first
sort groupid first
list
replace newvar = sum(newvar)
list
drop first
*--------------- 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 N515
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/