I have data (a dummy set provided here to make it simpler) that are stratified by id and by varC, as illustrated below.
I want to be able to find the maximum values of varA & varB stratified by id and varC and then using it in an equation (e.g. divide it by varB)
pseudocode by id varC:gen varD = max(varA)/max(varB)
I know I can do this using egen to find the max values of varA (stratified by id and varC) and dividing it by the maximum value of varB
QUESTION: Is there a way to do this without making a bunch of interim 'max' variables, or do I have to create all the max variables first and then create varD.
It is just not apparent to me how to do it and I have not been able to find a similar question to use as a place to start.
Many thanks
Don
I want to be able to find the maximum values of varA & varB stratified by id and varC and then using it in an equation (e.g. divide it by varB)
pseudocode by id varC:gen varD = max(varA)/max(varB)
I know I can do this using egen to find the max values of varA (stratified by id and varC) and dividing it by the maximum value of varB
QUESTION: Is there a way to do this without making a bunch of interim 'max' variables, or do I have to create all the max variables first and then create varD.
It is just not apparent to me how to do it and I have not been able to find a similar question to use as a place to start.
id | varA | varB | varC |
1 | 12 | 225 | 0 |
1 | 34 | 346 | 0 |
1 | 22 | 349 | 1 |
1 | 23 | 359 | 1 |
2 | 45 | 12 | 0 |
2 | 65 | 25 | 1 |
3 | 33 | 55 | 0 |
3 | 25 | 77 | 1 |
3 | 17 | 122 | 0 |
3 | 44 | 143 | 1 |
4 | 1 | 12 | 1 |
5 | 4 | 26 | 1 |
5 | 9 | 55 | 1 |
5 | 2 | 77 | 0 |
5 | 12 | 125 | 0 |
Don
Comment