I did the following for too many variables:
Variable 1:
Variable 2:
However, I would like to use the loop function to do this as I have too many variables. The following did not work:
Thanks in advance
Variable 1:
Code:
bysort year Industry: egen Industry_Mean_ROA = mean(ROA) bysort year firm: gen Industry_Adjusted_ROA = ROA - Industry_Mean_ROA
Code:
bysort year Industry: egen Industry_Mean_ROE = mean(ROE) bysort year firm: gen Industry_Adjusted_ROE = ROE - Industry_Mean_ROE
Code:
foreach v of varlist ROA ROE { bysort year firm: gen Industry_Adjusted_`v' = `v' - { bysort year Industry: mean(`v') } }