Hi everyone,
I am trying to use a cumulative multiplication formula over a 12 month window for 47 industries.
I am trying to create a loop to do this all at once in a rolling window.
I tried to look up a stata formula for cumulative multiplication but I could not find anything.
so
N12=Nk,t:t-11= [(1+Nk,t)*(1+Nk,t-1).........(1+Nk,t-11)]-1
where k indicates industry k and t indicates the specific month.
This is what I have:
foreach k of varlist N_Agric N_Food N_Beer N_Smoke N_Toys N_Fun N_Books N_Hshld N_Clths N_MedEq N_Drugs N_Chems N_Txtls N_BldMt N_Cnstr N_Steel N_Mach N_ElcEq N_Autos N_Aero N_Ships N_Mines N_Coal N_Oil N_Util N_Telcm N_PerSv N_BusSv N_Hardw N_Chips N_LabEq N_Boxes N_Trans N_Whlsl N_Rtail N_Meals N_Banks N_Insur N_RlEst N_Fin N_Other{
gen N12 = (`k'[_n] * `k'[_n-1]* `k'[_n-2]* `k'[_n-3]* `k'[_n-4]* `k'[_n-5]* `k'[_n-6]* `k'[_n-7]* `k'[_n-8]* `k'[_n-9]* `k'[_n-10]* `k'[_n-11])-1
}
does anyone know how to do this?
Thank you in advance!
I am trying to use a cumulative multiplication formula over a 12 month window for 47 industries.
I am trying to create a loop to do this all at once in a rolling window.
I tried to look up a stata formula for cumulative multiplication but I could not find anything.
so
N12=Nk,t:t-11= [(1+Nk,t)*(1+Nk,t-1).........(1+Nk,t-11)]-1
where k indicates industry k and t indicates the specific month.
This is what I have:
foreach k of varlist N_Agric N_Food N_Beer N_Smoke N_Toys N_Fun N_Books N_Hshld N_Clths N_MedEq N_Drugs N_Chems N_Txtls N_BldMt N_Cnstr N_Steel N_Mach N_ElcEq N_Autos N_Aero N_Ships N_Mines N_Coal N_Oil N_Util N_Telcm N_PerSv N_BusSv N_Hardw N_Chips N_LabEq N_Boxes N_Trans N_Whlsl N_Rtail N_Meals N_Banks N_Insur N_RlEst N_Fin N_Other{
gen N12 = (`k'[_n] * `k'[_n-1]* `k'[_n-2]* `k'[_n-3]* `k'[_n-4]* `k'[_n-5]* `k'[_n-6]* `k'[_n-7]* `k'[_n-8]* `k'[_n-9]* `k'[_n-10]* `k'[_n-11])-1
}
does anyone know how to do this?
Thank you in advance!
Comment