1iqv1g

Q: How I calculate industry mean or standard deviation of returns?

In accounting research, we have to calculate industry means and standard deviations. Thankfully, Stata has a beautiful function known as egen to easily calculate group means and standard deviations.

Let’s use our trusty auto.dta

*********************

clear

sysuse auto.dta

**Calculate the mean price by foreign/ domestic. bysort sorts the data so we can calculate the mean by groups.

bysort foreign: egen price_mean=mean(price)
**Calculate the standard deviation of price by foreign/ domestic
bysort foreign: egen price_sd=sd(price)
Advertisements