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   Eva Poen <[email protected]>
To   [email protected]
Subject   Re: st: Maximum length of a string expression in a program
Date   Mon, 16 Mar 2009 09:08:08 +0000

Davide,

the problem is in a part of your code that you are not showing. Your
program, so far, does not use evaluation (the evaluating equal sign).
See also here: http://statajournal.com/article.html?article=pr0045 .
As soon as you manipulate `regressors' with an equal sign, the limit
bites. Without it, you should be fine, as the following example shows.

Eva

************************************************
capture program drop mycommand
program mycommand
       syntax namelist [if] [in] [aweight fweight pweight] [, *]
       gettoken command 0 : namelist
       gettoken depvar regressors : 0
       `command' `depvar' `regressors' `if'  [`weight' `exp'] , `options'
end

* create 150 regressors
clear
set obs 5000
set seed 123
forvalues x = 1/150 {
 gen x`x' = invnorm(uniform())
}
gen eps = invnorm(uniform())
gen y = 5
forvalues x = 1/150 {
 replace y =  y + `x'*x`x'
}
replace y = y + eps

* use regress
regress y x*

* use mycommand
qui ds x*
mycommand regress y `r(varlist)'
************************************************


2009/3/16 Davide Cantoni <[email protected]>:
> Dear statalisters,
>
> 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.
> Specifically, my code looks like this
>
> *** begin code
>
> program mycommand
>        syntax namelist [if] [in] [aweight fweight pweight], ...
>
>        gettoken command 0 : namelist
>        gettoken depvar regressors : 0
>
>        `command' `depvar' `regressors' `if'  [`weight' `exp'], ...
>
>        ...
>
> end
>
> *** end code
>
> (to explain: the idea is to have a two-word command, where the second
> word is a regression command built-in in Stata. So, for example, one
> would run "mycommand areg y x1 x2 x3..." and then -mycommand- would
> use -areg- within its routine)
>
> 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, which of course can create
> problems. What would a savvy programmer to do avoid this problem? I
> cannot imagine that any list of regressors has to be shorter than 244.
>
> Thanks for your help and suggestions,
>
> Davide

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