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]

Re: st: new Stata package -lstrfun- lets you modify long local macros that contain strings using Mata string functions


From   Eric Booth <ebooth@ppri.tamu.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>, Dan Blanchette <dan.blanchette@duke.edu>
Subject   Re: st: new Stata package -lstrfun- lets you modify long local macros that contain strings using Mata string functions
Date   Mon, 16 Aug 2010 18:34:40 +0000

<>

Hey Dan:
Very cool new package.  One quick suggestion:

I think that these option descriptions in the help file:

subinstr(macname, "to", "from", n)
subinword(macname, "to", "from", n)

should be reversed to say:

subinstr(macname, "from", "to", n)
subinword(macname, "from", "to", n)

This seems to be the convention that is used elsewhere in Stata and this looks to be what -lstrfun- is already doing, ex:
**
local a  `c(pi)'
lstrfun new_mvar, subinstr(`"`a'"', "3", "[]", .)
di `"`new_mvar'"'
**
Also, I don't know how feasible it would be to add it, but it would be great to see some regex-type pattern matching allowed in some future version.  
((I was able to get the options " strmatch(macname, pattern) " and " strpos(macname, "needle") "  to work together to let help substitute a string based on a pattern, but in order to get it to match/substitute every instance of a pattern, I used looping and this doesn't allow string matching the pattern at the beginning or end of the macro to be treated differently as in regex))

~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754



On Aug 16, 2010, at 9:54 AM, Dan Blanchette wrote:

> Dear Statalist Members,
> 
> Thanks to Kit Baum, a new Stata package -lstrfun- is now available for download from the SSC:
> 
>  . ssc install lstrfun
> 
> 
> Description
> 
>  -lstrfun- allows you to modify local macros that contain strings using Mata's
>  string functions which are not restricted to the maximum length of strings
>  in Stata like the normal string functions in Stata are limited.  For example:
> 
>  If the length of the local macro m_test is 1,234 and you want to make it all
>  uppercase and you use the Stata string function upper():
> 
>    . local m_test= upper(m_test)
> 
>  then Stata will truncate m_test to the first 244 characters.  -lstrfun- will
>  not truncate m_test:
> 
>    . lstrfun m_test, upper(`"`m_test'"')
> 
>  If you are using Stata SE or Stata MP, then your setting of maxvar affects the
>  maximum number of characters in a macro.  The maximum number of characters in
>  a macro is only 1,081,511 when maxvar is set to 32767.  Stata's c-class values
>  will show you what your Stata session's limits are set to:
> 
>    . display c(maxvar)
>    5000
> 
>    . display  %11.0gc c(macrolen)
>    165,200
> 
>    . set maxvar 27000
> 
>    . display  %11.0gc c(macrolen)
>    891,200
> 
>  -lstrfun- can be very helpful when trying to modify value labels and notes in
>  Stata since values labels and notes are allowed to have more characters than
>  normal string functions are allowed to handle.
> 
> Here is the help page for -lstrfun- in html format that shows all the string functions -lstrfun- can use to modify a local macro or create a new local macro:
> 
>   http://fmwww.bc.edu/repec/bocode/l/lstrfun.html
> 
> Let me know if you have any questions,
> 
> Dan Blanchette
> Research Associate
> Center for Entrepreneurship and Innovation
> Duke University's Fuqua School of Business
> dan.blanchette@duke.edu
> 
> 
> 
> 
> 
> *
> *   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   |   Site index