Statalist The Stata Listserver


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

Re: st: string management questions


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: string management questions
Date   Wed, 09 May 2007 21:16:38 -0400

At 05:24 PM 5/9/2007, Wanli wrote:
I have two questions on string functions:
1. Is there some way to increase the limit of string length of 244? When I
create string from other string variables, I found some weird things happen.
Now I realize it's due to the length limit of string variable. I am using SE
9.2.
2. I asked this before. I have a string variable. One observation is like
"a, b, f, g, b, a, a, f, g, g". How do I create another variable which shows
no repeated values, i.e., "a, b, f, g". The sequence does not matter. Thank
you very much.
1. As far as I know, there is no way to increase that limit. There are a few matters to note:
a, that limit applies to both string variables and to string expressions, which are somewhat different concepts; see -help limits-.
b, if you can work with macros, the limit is much larger; but beware that some macro operations can be cast in terms of expressions (using "="), in which case that lower limit takes effect. (Some macro operations can be done either using expressions or not; it is usually better not to use expressions.)

2. I don't know how to do this in a variable. But, again, if you can do it in macros, it is easy. But you need to get rid of the commas -- which you can do with subinstr. Once that is accomplished, you can use the macro list facilities, in particular -local macro1: list uniq macro0-. See -help macrolists-. If these values really must reside in variables, you can loop through the observations, bring the value into macros, do the operation using the macrolist facilities as shown above, then store the value back into the variable. Note that looping through observations is usually not a good idea and usually not necessary. This might be an exception. But I'm not sure if there are other better options; maybe I've overlooked something.

I hope this helps.
--David

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index