Hi everyone,
I'm quite new to Stata so apologies if this question is "basic".
I have a panel with the following variables: (firm) ID, Industry Code, Year, and Income.
I would like to generate a variable called Risk which would be the standard deviation of Income for all firms within the same industry and for all previous years.
E.g. say the panel starts with year t, I want the standard deviation for all firms with the same value of Industry Code in year t; for year t+1 I want the standard deviation for year t AND t+1 etc.
I guess I need some kind of foreach loop but I'm really stuck here.
Thank you
Valentina
I'm quite new to Stata so apologies if this question is "basic".
I have a panel with the following variables: (firm) ID, Industry Code, Year, and Income.
I would like to generate a variable called Risk which would be the standard deviation of Income for all firms within the same industry and for all previous years.
E.g. say the panel starts with year t, I want the standard deviation for all firms with the same value of Industry Code in year t; for year t+1 I want the standard deviation for year t AND t+1 etc.
I guess I need some kind of foreach loop but I'm really stuck here.
Thank you
Valentina
Comment