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 on April 23, and its replacement, statalist.org is already up and running.


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

RE: st: RE: work with larger string length


From   tashi lama <ltashi32@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: work with larger string length
Date   Tue, 27 Mar 2012 19:39:03 +0000

Thank you Nick. 


> From: n.j.cox@durham.ac.uk
> To: statalist@hsphsun2.harvard.edu
> Date: Tue, 27 Mar 2012 17:14:23 +0100
> Subject: st: RE: work with larger string length
> 
> First taking your questions one by one: 
> 
> 1. since string limit is 244, what is it about extended function subinstr that makes string limitation non issue. Does extended function increase the acceptable string length which I think is unlikely?
> 
> I don't know what kind of answer you expect here, but the short answer is yes. It is a fact that using -subinstr()- rather than -: subinstr- bites as the limit on the length of strings in string expressions is 244 in all current flavours of Stata. See -help on limits-. I can't expand on why Stata is written this way; that's an interesting question to me too. 
> 
> 2. looks like the same question to me. 
> 
> 3. when I use length command to find the length of the string in stata12, I get unrecognized command. Any idea.
> 
> Works for me. I can't say what you did wrong, as you don't show any example code. 
> 
> . di length("frog")
> 4
> 
> Now I want to comment on your code
> 
> foreach x of varlist hits* {
> gen temp=`x'
> replace `x'=.
> egen tot_`x'=rowtotal(hits*)
> replace `x'=temp
> drop temp
> }
> 
> A better solution (in my view) is implied by advice given earlier in the thread you started previously. 
> 
> unab hitlist : hits* 
> foreach x of local hitlist { 
> local thislist : list hitlist - x 
> egen tot_`x' = rowtotal(`thislist')
> } 
> 
> 
> Nick 
> n.j.cox@durham.ac.uk 
> 
> tashi lama
> 
> I posted a question related to this earlier and received favorable answers although I am not sure if I completely understand the science. I have dared to post this question again. Any help will be highly appreciated. 
> 
> I have a dataset of some 48 variables and the nature of my problem obliges me to have all variables start with hit. when I ran this code, 
> 
> foreach x of varlist hit* {
> local varlist_new=subinstr("`varlist'", "`x'","",1)
> di "`varlist_new'"
> egen tot_`x'=rowtotal(`varlist_new')
> }
> 
> The problem was I did get answers but the upon close analysis, the answers were incorrect. I am assuming it must be because the length of my string variables exceed 244. Now, I was advised to use extended subinstr function, which seem to work. Further I wrote a code below, which also works. 
> 
> foreach x of varlist hits* {
> gen temp=`x'
> replace `x'=.
> egen tot_`x'=rowtotal(hits*)
> replace `x'=temp
> drop temp
> }
> 
> My question is 
> 
> 1. since string limit is 244, what is it about extended function subinstr that makes string limitation non issue. Does extended function increase the acceptable string length which I think is unlikely? 
> 
> 2. The code without subinstr works and again, it sounds like string limitation is a non issue. Again, is the code increasing the accepateble length of the string??
> 
> 3. when I use length command to find the length of the string in stata12, I get unrecognized command. Any idea. 
> 
> 
> *
> * 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