Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Challenging foreach problem


From   "Dudekula, Anwar" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Challenging foreach problem
Date   Sun, 13 Nov 2011 04:08:16 +0000

Dear Statlist reader , 


I am working on a patient dataset  with patients identification code observation( each row), and 15 variables containing ICD9 diagnosis codes ( string varaibles) .Part of the dataset if posted below 

For diseases of my interest
1)disease A with icd9 codes "350.2" "352.12" "368.58"  
2)disease B("354.15" "387.89" "369.56") ]

 I am using the foreach command 

foreach x in pdx sdx1 sdx2 sdx3 sdx4 sdx5 sdx6 sdx7 sdx8{
icd9 gen `x'disease A=`x', range"350.2" "352.12" "368.58")
}

foreach x in pdx sdx1 sdx2 sdx3 sdx4 sdx5 sdx6 sdx7 sdx8{
icd9 gen `x'disease B=`x', range"354.15" "387.89" "369.56")
}


Is there a way to combine the above two commands into a single foreach command as I have 15 diseases of interest ???? 


     +------------------------------------------------+
     |   pseudoid   pdx      sdx1     sdx2     sdx3   |
     |------------------------------------------------|
  1. | pseudoid1    566      555.0    569.49   V15.04 |
  2. | pseudoid2   555.9    300.4    276.8    729.1  |
  3. | pseudoid3    555.9    599.0    263.9    565.1  |
  4. | pseudoid4    555.0    997.4    560.1    560.9  |
  5. | pseudoid5   569.61   567.22   569.81   555.0  |
     |------------------------------------------------|
  6. | pseudoid6    997.4    511.9    512.8    555.9  |
  7. | pseudoid7    427.31   556.9    401.9    250.00 |
  8. | pseudoid8    780.97   585.6    584.9    572.3  |
  9. | pseudoid9    414.01   556.9    401.9    272.4  |
 10. | pseudoid10    552.21   556.9    568.0    V44.2  |
     +------------------------------------------------+


Thank you,Yours Sincerely,Anwar Dudekula, MD Clinical Instructor of Medicine, General Internal Medicine,University of Pittsburgh.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index