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]
Re: st: macros of multiple complex strings
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: macros of multiple complex strings
Date
Tue, 2 Jul 2013 23:39:46 +0100
My guess:
Your second code block first tries to interpret
replace lym = 1 if `textfield' == `proc'
as
replace lym = 1 if prncptx = LAPT STG/RESTG OVARIAN TUBAL/PRIM MAL 2ND LOOK
and Stata tries to make sense of this by looking for a variable (or
scalar) named
LAPT
and it fails. Hence the error. Stata didn't even look at the rest of
your text string. Stata bailed out at the first error.
The code should be
replace lym = 1 if `textfield' == "`proc'"
so that `proc' appears inside " " and is interpreted as you want as a
literal string.
You may well be thinking: But I supplied " " as delimiters. And so you
did, but Stata's habit is to strip delimiters, and you must put them
back.
Nick
[email protected]
On 2 July 2013 23:28, David Lockhart <[email protected]> wrote:
> I have a dataset with information on surgeries recorded by CPT codes. Each
> patient has up to 21 CPT codes in variables called cpt othercpt1 ...
> othercpt10 concpt1 ... concpt10.
>
> I also have several lists of CPT codes which include procedures of
> interest. For example, 6 codes which involve lymph node dissection (LND). I
> am trying to create a variable which has the value 1 if the surgery
> involved LND and 0 if it did not.
>
> But some codes are ambiguous, for example the code 58960 includes removal
> of tumor with or without LND. Each CPT code field has an accompanying text
> field which holds a brief text description describing the procedure, and
> sometimes this can disambiguate these codes. I have made a list of the
> values this text field takes on for the ambiguous codes and have selected
> those which I wish to count as indicating that LND was performed. But I'm
> having trouble setting up the code to do this.
>
> Here's what I'm trying that isn't working. The first loop works but the
> second does not.
>
> gen lym = 0
> foreach cptfield of varlist cpt othercpt* concpt*{
> foreach cptcode of numlist 38562 38564 38570 38571 38572 38589 38770
> 38780 58200 58210 ///
> 58548 58943 58951 58954 59548 {
> qui replace lym = 1 if `cptfield' == `cptcode'
> }
> }
>
> foreach textfield of varlist prncptx otherproc* concurr* {
> foreach proc in "LAPT STG/RESTG OVARIAN TUBAL/PRIM MAL 2ND LOOK" ///
> "RESECT RECUR GYN MAL W/LYM" "BSO W/OMNTC TAH DEBULKING W/LMPHADEC" ///
> "LAPS W/RAD HYST W/BILAT LMPHADEC RMVL T" "RAD ABDL HYST W/BI PEL
> LMPHADEC" ///
> "RESECTION RECRT MAL W/OMENTECTOMY PEL LMPHADEC" ///
> "LAPAROTOMY, FOR STAGING OR RESTAGING OF OVARIAN,"{
> replace lym = 1 if `textfield' == `proc'
> }
> }
>
> When I run this, I get an error that "LAPT not found". So, I can tell it
> is trying to split up that string into "words", but I don't understand why
> or how to get it to treat the strings as separate units.
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/