> -----Original Message-----
> From: Danielle H. Ferry [mailto:[email protected]]
> Sent: Thursday, February 20, 2003 10:39 AM
> To: StataList
> Subject: st: forvalues - irregular step sizes
>
>
> Hi,
>
> I would like to run the following loop, where I have a series
> of variables
> produced by a regression containing an interaction of
> state*popnLn*ttrend1.
> "popnLn" & "ttrend1" are continuous variables, but "state" is
> a categorical
> variable. Since the coding for "state" has irregular spacings
> (1, 5, 16, 20,
> 23, etc.) the loop fails. Is there a way to make it continue
> onto the next
> loop if, for example, a value of i=2 is not found?
>
> forvalues i = 5(1)54{
>
> test _Ist`i'XpoXtt
>
> scalar f`i' = r(F)
> scalar pr`i' = r(p)
>
> }
>
> Any help would be greatly appreciated!
Two options. First, only loop over the values you want:
foreach i in 1 5 16 20 23 {
<<do something>>
}
Second, -capture- the attempt to test:
forvalues i = 5(1)54 {
capture test _Ist`i'XpoXtt
if !_rc {
scalar f`i' = r(F)
scalar pr`i' = r(p)
local list "`list' `i'"
}
}
This code also leaves behind the macro list, which includes a list of
the valid codes, in case you need them for subsequent processing.
Nick WInter
*
* 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/