Hi all,

I am trying to create a mean population density variable for every observation in my dataset. Each observation has this basic structure:
Observation No. Province/State Return on Investment mean population density x3 (some other variable)
1 Delhi, Bengal 5.5 ?
2 Tamil Nadu, Kerala 7.9 ?
3 Kerala 6.8 ?
Therefore, any particular observation can span multiple provinces/states. I have population density data by state. I want to generate a "mean population density" variable for each observation. For example, the mean population density for Observation 1 will be the mean of the population densities in Delhi and Bengal.

How do I get Stata to go through every observation and perform the mean generating operation? It seems like I may have to use a loop of some kind, though I am not sure what's the easiest way.

Thank you!