Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: subinstr does not replace but repeats


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: subinstr does not replace but repeats
Date   Tue, 6 May 2008 22:25:52 -0400

Carlos Eduardo Hernandez Castillo <cehc84@hotmail.com>:
You will see in -help limits- that the limit on a string expression is
244 characters; when the length of the product of subinstr() reaches
244, bad things happen (note the size of the output of subinstr()
matters, not just the inputs).  However, the limit on characters in a
local macro is rarely binding (1,081,511 characters for you).  So try:

loc old "ide011 ide010 ide001 per001 per004 per008 edu007"
loc old "`old' edu004 ftr014 ftr014v ftr014a ftr020 mig006 mig002"
loc old "`old' mig005 mig001 ocu009 ocu008 ocu007 ocu006 ocu003 "
loc new: subinstr local old " " "_20051 ", all
di "`new'"

On Tue, May 6, 2008 at 10:01 PM, Carlos Eduardo Hernandez Castillo
<cehc84@hotmail.com> wrote:
>
>  Hello.
>
>
>  I am trying to use subinstr with a long string. However, I am not getting what I think I should be getting:
>
>
>  display subinstr("ide011 ide010 ide001 per001 per004 per008 edu007 edu004 ftr014 ftr014v ftr014a ftr020 mig006 mig002 mig005 mig001 ocu009 ocu008 ocu007 ocu006 ocu003 "," ","_20051 ",.)
>
>  ide011_20051 ide010_20051 ide001_20051 per001_20051 per004_20051 per008_20051 edu007_20051 edu00
>  > 4_20051 ftr014_20051 ftr014v_20051 ftr014a_20051 ftr020_20051 mig006_20051 mig002_20051 mig005
>  > _20051 mig001 ocu009ocu009 ocu008 ocu007 ocu006 ocu003
>
>
>  Notice that it works well UNTIL mig005. It does not work afterwards. It even repeats ocu009.
>
>  I am working with Stata SE 10 for Windows. I think that it may have to do with the length of the string. I have thought about using tokenize and then rebuild the modified string. However, I usually work with long strings and string functions, so doing this everytime would make my programs long and hard to read. Could you please help me to realize how can I solve my problem in an efficient way?
>
>  Thanks in advance.
>
>  Carlos Eduardo Hernández Castillo
>  Colombia
>
>
>
>  _________________________________________________________________
>  Explore the seven wonders of the world
>  http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE
>  *
>  *   For searches and help try:
>  *   http://www.stata.com/support/faqs/res/findit.html
>  *   http://www.stata.com/support/statalist/faq
>  *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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