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

st: Using "forvalues" vs. old "for"


From   [email protected]
To   [email protected]
Subject   st: Using "forvalues" vs. old "for"
Date   Mon, 30 Jun 2003 14:35:21 +0200

Dear Stata-listers,

I am running into problems when I try to "nest-loop"  using the old "for"
and, reluctantly, the new  "forvalues".   


My aim is to have the following tabulation:

for Y in num 1/6: for X in num 1/6: ta vnum mXachieved if site==Y &
mvvdate~=., row \  ta vnum mXachieved  if site==Y, row 

I get an error message I guess because the inside loop will only execute the
first tabulation, comes to the second and can not find "mXachieved"!!


If the command is modified to read:  

for Y in num 1/6: for X in num 1/6: ta vnum mXachieved if site==Y &
mvvdate~=., row \  for X in num 1/6: ta vnum mXachieved  if site==Y, row 

That yields the exact tabulation to breaking-up  the loop into two separate
processes as follows:

for Y in num 1/6: for X in num 1/6: ta vnum mXachieved if site==Y &
mvvdate~=., row 
for Y in num 1/6: for X in num 1/6: ta vnum mXachieved  if site==Y, row 


I tried to use the new "forvalues" as follows:

forvalues Y = 1(1)6 {
	2.	forvalues X = 1(1)6 {
			2.	ta vnum mXachieved if site==Y & mvvdate~=.,
row  
			3.	ta vnum mXachieved if site==Y, row }
	}

I get an error message  telling me:

unrecognised command:  2. invalid command name
r(199);



Many thanks for your suggestions in advance.

Amani




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