# st: Forvalues, syntax error

 From "Gauri Khanna" To statalist@hsphsun2.harvard.edu Subject st: Forvalues, syntax error Date Thu, 05 Jul 2007 13:25:17 +0000

Dear Stata List,

I have run into a syntax error r(198) after running the command - forvalues-.

The strange thing is that the code works when I use my entire dataset but I get this syntax error when I use a subset of the data. Since this is a syntax problem, my guess is that it is not a substantive issue but I am quite puzzled as to the problem with syntax. I have copied the code and the output for you to see. I am grateful for your help.

COMMANDS
***Regression***
set more off
set matsize 5000

use `allsvys1', clear
egen i=group(un_region2 sex_code) if excind!=1 & sex_code!=3 & total_age_group!=1 & agegrp==0
summarize i
local max1=r(max)
gen error1=.
gen error2=.
save `allsvys', replace

forvalues svy = 1/`max1' {
use `allsvys', clear
keep if i==`svy'

summarize smk_d
local maxsd=r(max)
if `maxsd'>=95 local maxsd=95
local minsd=r(min)
if `minsd'<=5 local minsd=5

summarize cig_d
local maxcd=r(max)
if `maxcd'>=95 local maxcd=95
local mincd=r(min)
if `mincd'<=5 local mincd=5

replace lgsmkd=ln((smk_d-(`minsd'-5))/((`maxsd'+5)-smk_d))
replace lgcigd=ln((cig_d-(`mincd'-5))/((`maxcd'+5)-cig_d))

replace agesmkd=midage*lgsmkd
replace agecigd=midage*lgcigd

list un_region2 in 1
list sex_code in 1

sw regress lgcigd lgsmkd midage agesmkd [aweight=sample_size] if excind!=1 & sex_code!=3 & total_age_group!=1 & totalind!=1 & agegrp==0 & source_code!=101692 & source_code!=101731 & source_code!=101712 & source_code!=101014 & source_code!=101711 & source_code!=101724, pr(0.05) lockterm1 hier
mark type if excind!=1 & sex_code!=3 & total_age_group!=1 & totalind!=1 & agegrp==0 & lgcigd!=. & lgsmkd!=. & source_code!=101014 & source_code!=101711 & source_code!=101724 & source_code!=101692 & source_code!=101731 & source_code!=101712
predict yhat1
replace r2noc=e(r2_a)
replace cig_d_est2 = ((`mincd'-5)+(`maxcd'+5)*exp(yhat1))/(1+exp(yhat1))
replace cig_d=min(cig_d_est2, cig_c, smk_d) if cig_d == . & cig_d_est2 != . & agegrp==0

**********************************************************************************************************************************
**********************************************************************************************************************************

sw regress lgsmkd lgcigd midage agecigd [aweight=sample_size] if type==1, pr(0.05) lockterm1 hier
predict yhat3
replace r2nos=e(r2_a)
replace smk_d_est2 = ((`minsd'-5)+(`maxsd'+5)*exp(yhat3))/(1+exp(yhat3))

replace trace22="typeconv cigd->smkd ok" if cig_d!=. & cig_d!=0 & smk_d == . & smk_d_est2 != . & smk_c==. & smk_d_est2>cig_d & agegrp==0
replace smk_d=smk_d_est2 if cig_d!=. & cig_d!=0 & smk_d == . & smk_d_est2 != . & smk_c==. & smk_d_est2>cig_d & agegrp==0
replace trace22="typeconv cigd->smkd cigd" if cig_d!=. & cig_d!=0 & smk_d == . & smk_d_est2 != . & smk_c==. & smk_d_est2<=cig_d & agegrp==0
replace smk_d=cig_d if cig_d!=. & cig_d!=0 & smk_d == . & smk_d_est2 != . & smk_c==. & smk_d_est2<=cig_d & agegrp==0

cap append using `finaltemp'
save `finaltemp', replace
}
invalid syntax
r(198);

OUTPUT
.
. ****Regression****
.
. set more off

. set matsize 5000

Current memory allocation

current memory usage
settable value description (1M = 1024k)
--------------------------------------------------------------------
set maxvar 5000 max. variables allowed 1.733M
set memory 500M max. data space 500.000M
set matsize 5000 max. RHS vars in models 191.154M
-----------
692.887M

.
. use `allsvys1', clear

. egen i=group(un_region2 sex_code) if excind!=1 & sex_code!=3 & total_age_grou

```p!=1 & agegrp==0
```
(9973 missing values generated)

. summarize i

Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
i | 0

. local max1=r(max)

. gen error1=.
(9973 missing values generated)

. gen error2=.
(9973 missing values generated)

. save `allsvys', replace
file C:\DOCUME~1\khannag\LOCALS~1\Temp\ST_0000001b.tmp saved

.
.
. forvalues svy = 1/`max1' {
2. use `allsvys', clear
3. keep if i==`svy'
4.
. summarize smk_d
5. local maxsd=r(max)
6. if `maxsd'>=95 local maxsd=95
7. local minsd=r(min)
8. if `minsd'<=5 local minsd=5
9.
. summarize cig_d
10. local maxcd=r(max)
11. if `maxcd'>=95 local maxcd=95
12. local mincd=r(min)
13. if `mincd'<=5 local mincd=5
14.
. replace lgsmkd=ln((smk_d-(`minsd'-5))/((`maxsd'+5)-smk_d))
15. replace lgcigd=ln((cig_d-(`mincd'-5))/((`maxcd'+5)-cig_d))
16.
. replace agesmkd=midage*lgsmkd
17. replace agecigd=midage*lgcigd
18.
. list un_region2 in 1
19. list sex_code in 1
20.
. sw regress lgcigd lgsmkd midage agesmkd [aweight=sample_size] if exci

nd!=1 & sex_code!=3 & total_age_group!=1 & totalind!=1 & agegrp==0 & source_c
ode!=101692 & source_code!=101731 & source_code!=101712 & source_code!=101014
& source_code!=101711 & source_code!=101724, pr(0.05) lockterm1 hier
21. mark type if excind!=1 & sex_code!=3 & total_age_group!=1 & totali

nd!=1 & agegrp==0 & lgcigd!=. & lgsmkd!=. & source_code!=101014 & source_code
!=101711 & source_code!=101724 & source_code!=101692 & source_code!=101731 & source_code!=101712
22. predict yhat1
23. replace r2noc=e(r2_a)
24. replace cig_d_est2 = ((`mincd'-5)+(`maxcd'+5)*exp(yhat1))/(1+exp(y

```hat1))
```
25. replace cig_d=min(cig_d_est2, cig_c, smk_d) if cig_d == . & cig_d

```_est2 != . & agegrp==0
```
26.
. *****************************************************************************

```*****************************************************
```
. *****************************************************************************

```*****************************************************
```
.
. sw regress lgsmkd lgcigd midage agecigd [aweight=sample_size] if type

```==1, pr(0.05) lockterm1 hier
```
27. predict yhat3
28. replace r2nos=e(r2_a)
29. replace smk_d_est2 = ((`minsd'-5)+(`maxsd'+5)*exp(yhat3))/(1+exp(y

```hat3))
```
30.
. replace trace22="typeconv cigd->smkd ok" if cig_d!=. & cig_d!=0 &

```smk_d == . & smk_d_est2 != . & smk_c==. & smk_d_est2>cig_d & agegrp==0
```
31. replace smk_d=smk_d_est2 if cig_d!=. & cig_d!=0

``` & smk_d == . & smk_d_est2 != . & smk_c==. & smk_d_est2>cig_d & agegrp==0
```
32. replace trace22="typeconv cigd->smkd cigd" if cig_d!=. & cig_d!=0

``` & smk_d == . & smk_d_est2 != . & smk_c==. & smk_d_est2<=cig_d & agegrp==0
```
33. replace smk_d=cig_d if cig_d!=. & cig_d!=0

``` & smk_d == . & smk_d_est2 != . & smk_c==. & smk_d_est2<=cig_d & agegrp==0
```
34.
. cap append using `finaltemp'
35. save `finaltemp', replace
36. }
invalid syntax
r(198);

Thank you.

Gauri

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! http://search.msn.com/

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