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

st: RE: RE: problem with forvalues


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: problem with forvalues
Date   Mon, 17 Jun 2002 12:23:22 +0100

Didier Fouarge

> > I want to loop a tabstat command to compute median income for a
> > number of years using
> > ‘forvalues’ in a do-file. According to the help function the
> > following should be allowed:
> > forvalues i = 1 2 5/10 {
> >  	tabstat Y`i’, by(country) s(p50)
> > }

> > However, I get the following error message:
> >
> > invalid syntax
> > r(198);
> >
> > By the way, I get the same error message using other commands
> > such as sum Y`i’.
> >
> > forvalues i = 1/10 { ...  works perfectly.
> >
> >

You have misread the help, although the point is very subtle.

-forvalues- cannot take arbitrary numlists.

It has its own very strict idea of a range, which must take just one of
various forms.

1 2 5/10

is not of any of the allowed forms for range, but a hybrid.

foreach i of num 1 2 5/10 {
	tabstat Y`i’, by(country) s(p50)
}

is the way to do it.

Nick
n.j.cox@durham.ac.uk


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index