Hi,

I am trying to find out mean of rainfall for period of 30 years for each of the 140 countries. For this, I'm using loop.

Variables that I'm using are: year (1984-2016), country( Names of 140 countries) and rainfall(for 30 years 140 countries).
Generating rain30 - 30 year average for each country
devrain- deviation of rainfall from 30 year average

Code:
foreach year = 1984/2016{
by(country): egen rain30 = mean(rainfall)
gen devrain = rain30- rainfall
}
I get invalid syntax as an error message.

Could someone please tell me where am I going wrong?

Thanks.