Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Odd results from wordcount


From   [email protected]
To   [email protected]
Subject   st: Odd results from wordcount
Date   Fri, 19 Dec 2003 14:54:54 +0100

Dear listers.

I am in the process of writing a short program which will repeat multiple
commands for many variables and combinations of variables. In general the
user spesifies a variable list and commands, and the commands are repeated
through all possible combinations of the variables.
To run the loops the correct number of times I need to know how many
variables are listed by the user. I do this through a wordcount of the
variablelist. However, the wordcount seems to be unreliable. The program
code and a transcript from part of the trace which illustrates the error,
follows. 

Part of the program code looks like this:

program redo
syntax [varlist] [if] [in],cmds(namelist) [lhs(varlist)] [all] [savegraph]
noisily display "varlist: `varlist'"
noisily display "cmds: `cmds'"
local antvar=wordcount("`varlist'")
noisily display "antvar: `antvar'"
.
.
.
end



Transcript from trace:

. redo periode01 periode02 periode03 periode04 periode05 periode06 periode07
periode08 periode09 periode10, cmds(logit lowess) lhs(dummis06mnd) all
--------------------------------------------------------------- begin redo
---
- syntax [varlist] [if] [in],cmds(namelist) [lhs(varlist)] [all] [savegraph]
- noisily display "varlist: `varlist'"
= noisily display "varlist: periode01 periode02 periode03 periode04
periode05 periode06 periode07 periode08 periode09 periode10"
varlist: periode01 periode02 periode03 periode04 periode05 periode06
periode07 periode08 periode09 periode10
- noisily display "cmds: `cmds'"
= noisily display "cmds: logit lowess"
cmds: logit lowess
- local antvar=wordcount("`varlist'")
= local antvar=wordcount("periode01 periode02 periode03 periode04 periode05
periode06 periode07 periode08 periode09 periode10")
- noisily display "antvar: `antvar'"
= noisily display "antvar: 9"
antvar: 9


Unless my eyes are cheating me, the macro `antvar' contains ten words, not
nine which is counted in this case. The error can be observed in other cases
too, apparently at higher values of wordcount (10 counts as 8 with other
variables). Any comments as to the cause of this problem would be greatly
appreciated.


On a side note, I did try looping using foreach, but had problems refering
to the macro-values from within the nested loops. So I went with forvalues
instead.

Hope you can help.


Sincerely yours,

Steinar Fossedal

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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