I have a dataset that looks like this:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str6 DUID double PID str8 DUPERSID str4 ICD10CDX "10001" 101 "10001101" "J00" "10001" 101 "10001101" "M76" "10001" 101 "10001101" "H52" "10001" 101 "10001101" "J32" "10001" 101 "10001101" "-9" "10001" 102 "10001102" "J00" "10001" 102 "10001102" "M54" end
I want to create a new variable say X from the variable ICD10CDX such that if if ICD10CDX=="J00"|ICD10CDX=="J32" for a given individual, then X=1. I will eventually reshape the data from long to wide format so that there is one observation per person and I want the X value for that person ( so if he had either condition J00 or J32, his X value is 1). I know I could reshape the dataset first and then create X but there are upto 70 different conditions and it will take a lot of typing.
0 Response to Creating new variable from old variable for each unit in panel data setting
Post a Comment