Statalist The Stata Listserver


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

st: Invalid syntax in forvalues loop


From   "Doogar, Rajib" <[email protected]>
To   <[email protected]>
Subject   st: Invalid syntax in forvalues loop
Date   Wed, 8 Feb 2006 09:40:13 -0600

Dear List

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?

Many thanks!

r.

Rajib Doogar,
Department of Accountancy,
The University of Illinois at Urbana-Champaign
1206 S. Sixth Street, Champaign, IL 61820
Ph: 217.244.8083, Fax: 217.244.0902
http://www.cba.uiuc.edu/doogar



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