Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: Challenging foreach problem


From   "Dudekula, Anwar" <dudekulaan@upmc.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index