Hello,
I am using a panel dataset. It both id and ic variable (ic: income category: HI, LI, LMI, UMI)
I want to write a loop that performs a dickeyfuller test for each id in ic. The following table summerizes the data:

ic id
HI 1 to 42
LI 43 to 61
LMI 62 to 86
UMI 87 to 118

The loop is as follows:
use si1981, clear
sort ic cc year
egen id1=group(ic cc)
encode ic, gen(ic1)

foreach i of numlist 1/4 {
foreach j of numlist 1/42 43/61 62/86 87/118 {
tab ic id if id1==`i'
dfuller gcf, drift lags(4), if ic1==`i' & id1==`j'
}
}
*

The above code works for first ic (i.e., HI). I want the double-loop to run the test for all ids in each ic.
I am a beginner in looping. I was wondering if local or global can help me out.

Thank you in advance.