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

From |
Eva Poen <eva.poen@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Maximum length of a string expression in a program |

Date |
Mon, 16 Mar 2009 14:00:17 +0000 |

Davide, I think you can use the macro list commands for your problem, see -help macrolists-. However, wouldn't it be easier to just define a constraint and apply it to the regression? Like forvalues k=1/`=`nr'' { local thisreg : word `k' of `regressors' constraint define `k' `thisreg'=0 } Then you can call your regression command with the constraint option , e.g. regress `depvar' `regressors', constraint(1) Eva 2009/3/16 Davide Cantoni <davide.cantoni@gmail.com>: > Dear Maarten, Eva, > > thanks for your suggestions. So I found out that, as you pointed out, > the problem in my file is not the line containing > > `command' `depvar' `regressors' `if' [`weight' `exp'] , `options' > > But rather two other lines: > > *** > local regressors=trim("`regressors'") > *** > > and > > *** > local nr=wordcount("`regressors'") > foreach k of numlist 1(1)`nr' { > ... > local regrs_no``k'' = subinword("`regressors'","``k''","",.) > ... > } > *** > > I do not have instances in my code where I evaluate the string with an > = sign. But these two lines seem to be the stumbling stone. The first > one is just for cosmetic reasons, and I can merrily dispense with it. > In the other case the stumbling stone is -subinword-, not -wordcount-. > What I am doing there is eliminating one of the regressors at a time > (in order to run the regression with the imposed "null hypothesis" of > the corresponding beta to be zero). But Stata does not seem to like > subinword when the list is too long. What can I do there so get around > this problem? > > Thanks again, > > Davide > > On Mon, Mar 16, 2009 at 5:10 AM, Maarten buis <maartenbuis@yahoo.co.uk> wrote: >> >> --- On Mon, 16/3/09, Davide Cantoni wrote: >>> I have a question related to programming a new program/ado >>> file. I am encountering the problem that one of the >>> arguments of my program might be too long as a string, >>> going beyond the limit of 244 characters. >> <snip> >>> I am encountering problems when running -mycommand- with a >>> list of regressors that is longer than 244 characters. >>> Then, the list is arbitrarily truncated after that limit. >> >> You have to be a bit careful not to evaluate the local >> containing such a long string (i.e. avoid using the "=" when >> defining a local), but otherwise there should not be a >> problem with -gettoken- or the extended macro functions (I >> always type -help macro- and follow the link to the helpfile >> for the extended macro functions), even if the local surpasses >> the 244 tokens limit. This is illustrated in the example >> below: >> >> *------------ begin example ------------------- >> forvalues i = 1/60 { >> local lstring "`lstring' very" >> } >> local lstring "`lstring' long string" >> >> // the string has more than 244 characters: >> di `: length local lstring' >> >> // -gettoken- works: >> gettoken first rest : lstring >> di `:length local first' >> di `:length local rest' >> *------------- end example -------------------- >> (For more on how to use examples I sent to the Statalist, see >> http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html ) >> >> Hope this helps, >> Maarten >> >> ----------------------------------------- >> Maarten L. Buis >> Institut fuer Soziologie >> Universitaet Tuebingen >> Wilhelmstrasse 36 >> 72074 Tuebingen >> Germany >> >> http://home.fsw.vu.nl/m.buis/ >> ----------------------------------------- >> > * > * 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/

**References**:**Re: st: Maximum length of a string expression in a program***From:*Davide Cantoni <davide.cantoni@gmail.com>

- Prev by Date:
**st: New package -haif- on SSC** - Next by Date:
**Re: st: Maximum length of a string expression in a program** - Previous by thread:
**Re: st: Maximum length of a string expression in a program** - Next by thread:
**Re: st: Maximum length of a string expression in a program** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |