I have been trying to find a solution to this, but haven't found it (or haven't understood that it does what I am looking for when I have seen it), so I am posting here. Apologies if this question is a bit rudimentary!
I have a variable called sequence that takes on integer values 0 to 7. I want to be able to generate some summative information about this by student and term. For example, I can find the maximum value of sequence for each student per term by writing:
bysort StudentID Term : egen maxenrollseq=max( sequence )
This works as intended. But now I want to generate the maximum value of sequence (again by student by term) for which the value of another variable is 1. I just can't figure out how to do this?
For example, considering the follow made up data (where blank cells are missing data):
I would want student 1 to have a value of 3 for the maxseqvar value in term 1, and to have maxseqvar missing for term 2 (so that the new data would be):
Thanks in advance for any help!
I have a variable called sequence that takes on integer values 0 to 7. I want to be able to generate some summative information about this by student and term. For example, I can find the maximum value of sequence for each student per term by writing:
bysort StudentID Term : egen maxenrollseq=max( sequence )
This works as intended. But now I want to generate the maximum value of sequence (again by student by term) for which the value of another variable is 1. I just can't figure out how to do this?
For example, considering the follow made up data (where blank cells are missing data):
StudentID | Term | sequence | var |
1 | 1 | 3 | 1 |
1 | 1 | 4 | 0 |
1 | 1 | 4 | |
1 | 2 | 4 |
StudentID | Term | sequence | var | maxseqvar |
1 | 1 | 3 | 1 | 3 |
1 | 1 | 4 | 0 | 3 |
1 | 1 | 4 | 3 | |
1 | 2 | 4 |
Comment