Hi,
I would like to calculate the total number of months spent in prison by summing up the time in months spent for each unique “episode” in prison. I have three variables
I have tried the following:
which creates a maximum column, but I am not sure how to then add up the total month without double counting.
The column I am trying to produce is total_months (I have manually calculated it in the data example below to demonstrate)
I would like to calculate the total number of months spent in prison by summing up the time in months spent for each unique “episode” in prison. I have three variables
- Unique person ID
- Prison episode
- The number of months spent in prison
I have tried the following:
Code:
bysort ID prison_ep: egen max=max(months)
The column I am trying to produce is total_months (I have manually calculated it in the data example below to demonstrate)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str1 ID byte(prison_ep Months) float(max total_months) "a" 1 2 26 26 "a" 1 14 26 26 "a" 1 26 26 26 "b" 1 10 10 26 "b" 2 4 16 26 "b" 2 16 16 26 "c" 1 6 6 6 "d" 1 10 10 25 "d" 2 10 10 25 "d" 3 2 5 25 "d" 3 5 5 25 end
Comment