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

st: problem with -forvalues-


From   [email protected]
To   [email protected]
Subject   st: problem with -forvalues-
Date   Fri, 27 Sep 2002 10:16:39 -0700

Dear Statalisters--

I have been using -for- for a very long time now, and like it's
capabilities. However, I know it has its limits, and doesn't with a very
complicated sequence of commands.

I recently read Nick Cox' wonderful "Speaking Stata" column, and decided to
try and use -foreach- -forval-, instead of -for-. I have run into problems
with -forval-.

When my numlist is of the form "1 0", "0 1", "1", -forval- complains about
"invalid syntax". It works with "0/1" or "1(-1)0". With "1/0" it doesn't
complain, but displays no results.

-for-, on the other hand, works with all of the above.


Here is the small dataset I was using:

. input fail coag bleed pop

      fail       coag      bleed        pop
  1. 0 0 0 1403
  2. 0 0 1 2
  3. 0 1 0 191
  4. 0 1 1 1
  5. 1 0 0 384
  6. 1 0 1 8
  7. 1 1 0 241
  8. 1 1 1 22
  9. end

And here are the problematic commands:


. forval v = 1/0 {tab fail coag [fw=pop] if bleed==`v'}

. capture noi forval v = 1 0 {tab fail coag [fw=pop] if bleed==`v'}
invalid syntax

. capture noi forval v = 0 1 {tab fail coag [fw=pop] if bleed==`v'}
invalid syntax

. capture noi forval v = 1   {tab fail coag [fw=pop] if bleed==`v'}
invalid syntax


Is this a "bug", a "feature", or am I missing something here?

Thanks for your help,
--Estie Hudes

Estie Sid Hudes, PhD MPH
University of California 
Prevention Sciences Group &
  Center for AIDS Prevention Studies
74 New Montgomery Street, Suite 600
S.F. CA 94105
phone: 415.597.9126
fax: 415.597.9194
email: [email protected]
Web: http://www.epibiostat.ucsf.edu/capsweb/people/hudesbio.html


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