Statalist


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

st: Re: replace if and too many literals error


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: replace if and too many literals error
Date   Sat, 28 Feb 2009 10:05:47 +0100

<>

You may want to use the methods in http://www.stata.com/support/faqs/data/selectid.html

-inlist- is probably not a way out for you as it only takes up to 10 string arguments...

What is weird is that when I move the endpoint in my -forvalues- loop to 51, Stata complains for the first time with -error 130-.

*******
clear*
input str20 mystring
thisisonestring
thisisasecondstring
thisisathirdstring
end

local myif "strmatch(mystring,"string_1") "

forv i=2/50{
local myif "`myif' | strmatch(mystring,"string_`i'")"
}

ma di

replace mystring="string_standard" if `myif'
********


The -search r(130)- file then says that "more than 500 dyadic operators" are to blame for the problem. Yet when I look up under -h limits-, the "# of dyadic operators in an expression " is 800 for my version...


HTH
Martin
_______________________
----- Original Message ----- From: "Matthew Hamilton" <mwhamilton@gmail.com>
To: "Statalist" <statalist@hsphsun2.harvard.edu>
Sent: Saturday, February 28, 2009 12:41 AM
Subject: st: replace if and too many literals error


Here's a simple problem I bet many novices like me have encountered. I
want to standardize the values of a string variable in my data called
"labtest." The approach I'm taking is this:

replace labtest="string_standard" if strmatch(labtest,"string_1") |
strmatch(labtest,"string_2") | ... | strmatch(labtest,"string_N")

Where strings 1 through N are unwanted variants of the standard string
I'm trying to impose. When N (the number of logical conditions above)
is larger than 13, I get the error message "too many literals." But
the system limit for number of string literals in an expression is
512, and the limit for numeric literals is supposed to be 300. (For my
version, IC v10.) Both limits are much larger than 13.

1. What's the problem?
2. Is there a more elegant way to standardize messy string variables?
(Mine are write-in responses from a survey.)

Thanks for your consideration.
*
*   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/


*
*   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   |   What's new   |   Site index