I have a small dataset as follows,
clear
input schid person_id math_score
1 1 89
1 11 67
1 12 99
2 1 100
2 11 88
2 12 85
2 13 95
end
I want to create a new variable called partial_sum, which should be equal to the sum of the values of math_score except for the 1st observation within schid. For example, when schid=1, the partial_sum=67+99=176; when schid=2, the partial_sum=88+85+95=268 Can someone help me with the Stata code? Thank you!
clear
input schid person_id math_score
1 1 89
1 11 67
1 12 99
2 1 100
2 11 88
2 12 85
2 13 95
end
I want to create a new variable called partial_sum, which should be equal to the sum of the values of math_score except for the 1st observation within schid. For example, when schid=1, the partial_sum=67+99=176; when schid=2, the partial_sum=88+85+95=268 Can someone help me with the Stata code? Thank you!

Comment