Hello, I have a series of loops. Right now they are set to display, but I want them to write the data to a xls file to create a table. I have tried messing around with eststo but I can't seem to get it yet. I guess I would have to replace the display with a different command...

egen id=group(thing otherthing)
forvalues i=1989(1)2003{
display `i' distinct id if year1==`i'
}
forvalues i=1989(1)2003{
display `i' distinct id if urban==1 & year1==`i'
}
forvalues i=1989(1)2003{
display `i' distinct id if urban==3 & year1==`i'
}