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

st: Re: Odd results from wordcount


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: Re: Odd results from wordcount
Date   Fri, 19 Dec 2003 08:54:08 -0600

Steinar,

It does appear that -wordcount- has a limit on it.  An alternative method would
be to use the extended macro functions.  Adding this line to your code:

 local number : word count `varlist'

seems to give the correct count.  For example, simplifying your code to

program redo
syntax [varlist]
local antvar = wordcount("`varlist'")
noisily display "antvar: `antvar'"

local number : word count `varlist'
display in gr "Number of variables = `number'"

end


The results:

. set obs 100
obs was 0, now 100

. forva i = 1/1000 {
  2. gen x`i' = uniform()
  3. }

. redo x*
antvar: 64
Number of variables = 1000

Hope this helps,
Scott


----- Original Message ----- 
From: <[email protected]>
To: <[email protected]>
Sent: Friday, December 19, 2003 7:54 AM
Subject: st: Odd results from wordcount


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

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