Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Invalid syntax in forvalues loop


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Invalid syntax in forvalues loop
Date   Wed, 8 Feb 2006 15:45:44 -0000

forvalues x in 1/28 { 

is not legal. Try 

forvalues x = 1/28 { 

Nick 
[email protected] 

Doogar, Rajib
 
> Can someone please tell me why the following code produces an "Invalid
> Syntax r(198)" error and how to fix it?
> ===
> gen newvar=0 if oldvar ~=.
> forvalues x in 1/28 {
> quietly summ oldvar if myvar==`x', det
> replace newvar=1 if (oldvar < r(p1) | oldvar > r(p99)) & myvar==`x'
> } 
> ===
> I am running Stata/SE 8.2 for Windows.
> 
> In case this helps, I have tried manually typing in:
> ===
> gen newvar=0 if oldvar ~=.
> quietly summ oldvar if myvar==1, det
> replace newvar=1 if (oldvar < r(p1) | oldvar > r(p99)) & myvar==1
> quietly summ oldvar if myvar==2, det
> replace newvar=1 if (oldvar < r(p1) | oldvar > r(p99)) & myvar==2
> etc...
> ===
> and I get the desired outcome, but when I run the forvalues 
> loop, things
> crash. What am I doing wrong?

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