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   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Maximum length of a string expression in a program
Date   Mon, 16 Mar 2009 14:21:16 +0000 (GMT)


-----------------------------------------
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/



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