Dear statalisters,
I‘ve got multiple records per person and want to calculate some kind of cumulative exposure index per person. I’ve got a variable called “exposure” and want to create a new variable called “cum_exposure”. Each observation in the cum_exposure variable should give the sum of all previous cells in the exposure column (but per person). So something like this:
Id Exposure list Cum.Exposure
1 10 1 10
1 14 2 24
1 15 3 39
2 8 1 8
2 10 2 18
2 15 3 32
I’ve tried this:
.by id: gen list=_n
.gen cum_exposure=.
.replace cum_exposure= exposure[1] if list==1
.replace cum_exposure= exposure[1] + exposure [2] if list==2
.replace cum_exposure= exposure[1] + exposure [2] + exposure[3] if list==3
But how can I do this more efficiently? In a loop for example?
Thanks,
Raoul
Raoul Reulen
Cancer Research UK Graduate Training Fellow
Centre for Childhood Cancer Survivor Studies
Department of Public Health & Epidemiology
University of Birmingham
Birmingham
B15 2TT
tel.: +44 (0)121 414 4946
fax.: +44 (0)121 414 7923
email: [email protected]
website: www.bccss.bham.ac.uk
*
* 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/