Dear Statalist-members,

I have a bit of a beginner question: I have an unbalanced panel of several hundred localities, which I observe over several years, and I would like to do 2 things:
1) create a new set of variables containing locality-specific time trends. I know I could just interact localities with the time indicator, like
Code:
c.year##i.locality
and include this in the xtreg command, but I want to create a set of new variables containing the locality-specific time trends because of 2).
2) I then want to create the 2,3,4 and 5th polynomials of these locality-specific time trends.
Of course, I could manually create the time trends, but the number of localities is just too large. I am sure there is a more "elegant" way...

Thank you very much

Felix