Statalist


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

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


From   Davide Cantoni <[email protected]>
To   [email protected]
Subject   Re: st: Maximum length of a string expression in a program
Date   Mon, 16 Mar 2009 11:04:59 -0400

Dear Maarten, Eva,

thanks a lot for your comments. I should have added that actually I
have a -tokenize- in there, otherwise my loop would not work. So in
the original I have

***
local nr=wordcount("`regressors'")
tokenize `regressors'
foreach k of numlist 1(1)`nr' {
     ...
     local regrs_no``k'' = subinword("`regressors'","``k''","",.)
     ...
}
***

Regarding your suggestion, Maarten: I think I understand it, but it is
doing exactly the opposite of what I want: it is keeping regressor
``k'', not eliminating it, as I try to do in the code above. Thanks in
any case for your other suggestion.

Eva: thanks for your suggestion to use the constraint option. I will
try that, that sounds promising.

Davide

2009/3/16 Maarten buis <[email protected]>:
>
>
> -----------------------------------------
> Maarten L. Buis
> Institut fuer Soziologie
> Universitaet Tuebingen
> Wilhelmstrasse 36
> 72074 Tuebingen
> Germany
>
> http://home.fsw.vu.nl/m.buis/
> -----------------------------------------
>
>
> --- On Mon, 16/3/09, Davide Cantoni <[email protected]> wrote:
>> 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''","",.)
>>      ...
>> }
>> ***
>>
>> But these two lines seem to be the stumbling stone.
>
> The first you can solve by replacing it with
>
> local regressors : list retokenize regressors
>
> or
>
> unab regressors : `regressors'
>
> The latter also unabreviates the names of your regressors.
>
> The second you can solve by replacing it with
>
> local nr : word count `regressors'
> tokenize `regressors'
> forvalues k = 1/`nr' {
>    local regrs_no`k' = "``k''"
> }
>
> -tokenize- breaks the string contained in the local
> `regressors' up in bits and puts them in the locals
> `1', `2', `3', etc. Within the -forvalues- loop the
> local `k' will sequentially contain the numbers 1,
> 2, 3, etc. So, if the first variable is called x,
> then in the first itteration of this loop the line
> -local regrs_no`k' = "``k''"- will read:
>
> local regrs_no1 = "`1'"
>
> This still contains a local macro, so Stata reads
> again, and sees:
>
> local regrs_no1 = "x"
>
> That is why on the left side you only need `k'
> and on the right side you need ``k''. You also
> need the double quotes (" ") to make sure that
> Stata knows that you want the variables name
> and not the value of the first observation on
> the variable x.
>
> Hope this helps,
> Maarten
>
>
>
>
> *
> *   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index