Hi everyone!
I am using stata13
in my data set I have:
variable "patientmrn" where each value appears twice
each value is further defined by variable "ctdivolbodymgy" which has either a higher or lower numerical variable
like this:
I want to generate a new variable "scantype" where for every value for "patientmrn", the higher value for "ctdivolbodymgy" has value "ccta"
and the lower value for "ctdivolbodymgy" has value "cacs", to create a data set that will look like this:
I have tried sorting my data set using:
I keep getting error "invalid syntax r(198);"
Any help would be greatly appreciated.
Thank you, in advance, for your help and expertise.
I am using stata13
in my data set I have:
variable "patientmrn" where each value appears twice
each value is further defined by variable "ctdivolbodymgy" which has either a higher or lower numerical variable
like this:
patientmrn | ctdivolbodymgy |
11111 | 7 |
11111 | 1.6 |
2222 | 8.5 |
2222 | 2.8 |
and the lower value for "ctdivolbodymgy" has value "cacs", to create a data set that will look like this:
patientmrn | ctdivolbodymgy | scantype |
11111 | 7 | ccta |
11111 | 1.6 | cacs |
2222 | 8.5 | ccta |
2222 | 2.8 | cacs |
sort patientmrn ctdivolbodymgy
gen scantype=.
replace scantype = "ccta" if max(ctdivolbodymgy), by(patientmrn)
Any help would be greatly appreciated.
Thank you, in advance, for your help and expertise.
Comment