Good morning
I would like to report a series of annual variations using a loop.
This is my initial situation:
Code:
gen TOTIMMOVAR2015=(TOTIMMO2015-TOTIMMO2014)/abs(TOTIMMO2014)
*
gen TOTIMMOVAR2016=(TOTIMMO2016-TOTIMMO2015)/abs(TOTIMMO2015)
*
gen TOTIMMOVAR2017=(TOTIMMO2017-TOTIMMO2016)/abs(TOTIMMO2016)
*
gen TOTIMMOVAR2018=(TOTIMMO2018-TOTIMMO2017)/abs(TOTIMMO2017)
*
gen TOTIMMOVAR2019=(TOTIMMO2019-TOTIMMO2018)/abs(TOTIMMO2018)
My goal (as an assignment for the university) is to report this code in the form of a loop.
To do this I thought up this code:
Code:
local Year1=2015
local YearN=2019
forvalues y=`Year1'(1)`YearN'  {
    gen TOTIMMOVAR`y'=(TOTIMMO[`y']-TOTIMMO[`y'-1])/abs(TOTIMMO[`y'-1])
}
But unfortunately it doesn't work.
Thank you in advance for any help or suggestions!