Dear Stata Expert
I would much appreicate your help on this issue.
In a dataset where variabled DX1 - DX5
A specific procedure was coded with ICD code Howe want to replace that code in the whole dataset with another ICD code.
Wonder which loop function would do that.
Meaning, to look up all variables from DX1 up to DX5 and automatically capture any ICD with the original procedure code and replace it with the new one.
For example, i want to replace whatever ICD value coded in any of the variables DX1 up to DX5 that is equal to "41011" to be automatically converted to "41091" . Another level, if want to capture any of the values "41071" "41402" "41401" "4280" "42821" and replace it with "41091" . (these are aribitary chosen values just for demonstration)
I wonder which loop function would do that.
Thanks a lot



----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str5(DX1 DX2 DX3 DX4 DX5)
"41091" "51881" "0389"  "99592" "42833"
"41001" "42821" "78551" "4280"  "4271"
"41071" "78551" "2761"  "40390" "73016"
"41011" "42823" "5809"  "5854"  "41401"
"41041" "78551" "56881" "9980"  "2851"
"41071" "25000" "4019"  "41401" " "    
"41051" "78551" "42511" "2449"  "3051"
"41071" "4019"  "41401" "2449"  "7242"
"41041" "3051"  "41401" "V6549" " "    
"41031" "2724"  "42789" "3051"  "V173"
"41071" "42843" "5849"  "51852" "41401"
"41071" "41401" "4019"  "2724"  "42611"
"41041" "4260"  "25002" "3051"  "2724"
"41071" "41401" "3960"  "4293"  "4272"
"41071" "41401" "4019"  "27503" "3051"
"41071" "2762"  "4280"  "5849"  "5853"
"41071" "42821" "41401" "4148"  "4280"
"41071" "41401" "4019"  "2449"  "2724"
"41091" "2875"  "41401" "2724"  "4019"
"41071" "40200" "5849"  "5920"  "41401"
"41071" "5849"  "41401" "79029" "4019"
"41041" "25000" "2724"  "41401" "4142"
"41091" "41401" "4019"  "2720"  "4439"
"41071" "2724"  "27800" "4019"  "49390"
"41091" "41401" "25000" "V1582" "496"  
"41071" "42833" "99672" "42518" "4280"
"41071" "41402" "41401" "4280"  "42821"
"41001" "4280"  "42820" "41401" "4148"
"41041" "99664" "41401" "0413"  "25002"
"41071" "29620" "41401" "34690" "2724"
"41071" "4254"  "41401" "4019"  "2724"
"41041" "41401" "4142"  "2724"  "42789"
"41071" "41401" "25000" "4019"  "2724"
"41071" "41401" "2449"  " "     " "    
"41021" "99672" "41401" "4019"  "2724"
"41071" "41402" "4142"  "42830" "4280"
"41071" "41401" "4019"  "25000" "73300"
"41041" "51881" "486"   "42841" "78551"
"41041" "30000" "4019"  "4240"  "V1582"
"41071" "41401" "185"   "5718"  " "    
"41071" "41401" "4019"  "2724"  "30501"
"41041" "51851" "99739" "2851"  "41401"
"41031" "2449"  "41401" "3051"  "4019"
"41071" "2761"  "41401" "4148"  "4019"
"41071" "41042" "2724"  "43889" "4019"
"41041" "42789" "V1582" "V1046" "V1301"
"41011" "51881" "78551" "4275"  "4271"
"41071" "41401" "4019"  "496"   "30400"
"41011" "2948"  "5859"  "V1582" "2724"
"41071" "4271"  "41401" "4019"  "7859"
"41071" "41401" "4019"  "3051"  "27800"
"41071" "41405" "25000" "2724"  "V1582"
"41071" "41401" "2724"  "42769" "2720"
"41071" "2724"  "41401" "311"   "30000"
"41011" "412"   "41401" "4019"  "2724"
"41041" "42613" "2720"  "41401" " "    
"41041" "42741" "78550" "99801" "99601"
"41071" "25002" "4254"  "41401" "3051"
"41041" "41401" "496"   "3051"  "2724"
"41041" "3051"  "41401" " "     " "    
"41011" "4240"  "2724"  "41401" "60000"
"41071" "4370"  "2662"  "2841"  "41401"
"41071" "99812" "41401" "4019"  "2724"
"41011" "2859"  "V667"  "3051"  "4275"
"41031" "40391" "V5867" "V4511" "3572"
"41071" "42821" "5849"  "5855"  "58881"
"41041" "7100"  "41401" "4019"  "2724"
"41041" "2722"  "3051"  "4589"  "49390"
"41071" "41404" "41401" "V066"  "4019"
"41021" "4142"  "7840"  "V5867" "27652"
"41041" "25000" "4271"  "4264"  "99672"
"41011" "41401" "3051"  "2724"  "4019"
"41071" "4254"  "V0382" "V4502" "4019"
"41071" "41401" "25000" "4019"  "V1581"
"41071" "41401" "25000" "2724"  " "    
"41071" "42823" "41401" "43310" "3051"
"41021" "25062" "2720"  "2724"  "27800"
"41011" "41401" "V5866" "2449"  "7109"
"41071" "42789" "32723" "3051"  "4264"
"41041" "2724"  "27800" "41401" "V5866"
"41071" "2768"  "2851"  "41401" "496"  
"41071" "42821" "36043" "4280"  "41401"
"41041" "41401" "2724"  "4019"  "725"  
"41011" "29620" "41401" "2724"  "4019"
"41071" "41404" "41401" "4142"  "2724"
"41071" "2761"  "41401" "4142"  "25002"
"41071" "40390" "5852"  "30000" "412"  
"41071" "25002" "4019"  "2724"  "41401"
"41071" "2724"  "41401" "V4582" "4019"
"41061" "27800" "41401" "4019"  "3051"
"41011" "41401" "V1302" " "     " "    
"41071" "2761"  "3051"  "V4364" "30001"
"41011" "4142"  "41401" "4019"  "3051"
"41051" "42821" "4280"  "2724"  "4011"
"41041" "4019"  "3659"  "41401" "V4582"
"41071" "34590" "30981" "27800" "31401"
"41041" "42741" "4275"  "41401" "4019"
"41041" "V4582" "412"   "4019"  "2720"
"41071" "4168"  "4280"  "41401" "V4582"
"41040" "V4582" "4019"  "4142"  "41402"
end
------------------ copy up to and including the previous line ------------------