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: Extracting substrings from variables.


From   Amal Khanolkar <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Extracting substrings from variables.
Date   Fri, 25 May 2012 11:45:59 +0000

Hello all,

Im trying to generate a new variable using 'stubs' or 'substrings' of a combination of letters and numbers to indicate what I would like to be included in the new variable.

For example I have a variable 'Diagnoses' that contains all ICD 9 & 10 diagnoses for subjects included in the dataset. I would however only like to extract those subjects with diagnoses starting with the numbers '637' and '642' and 'O1' (the last being a combination of the letter O and number 1).

Thus I will have a new variable with subjects with certain specific diagnoses starting with the numbers/letters indicated above. I should also add I would like to specify that '637' and '642' above are just the stating numbers and might include other letters/numbers following it which is ok.

I've tried doing the above using the 'regexs' command:

gen preght = regexs(0) if regexm(mdiag1x, "[^637] | [^642] | [^O1]")

Could you give some tips on how this can be further improved or other easier commands I could use?

Thanks!

/Amal.



*
*   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