Dear Statalisters,
I am using Stata for Windows 12.1. I have created new1 and new2 in the attached dataset using the following commands:
/* sum of exports by ccode for each isic category across years */
/* sum of exports by ccode for each isic category for different years */
I would like to create the average values of y for each isic category over the years, as well as the average of x1. However, the following code:
calculates the average value of exports for ccode over different years for each isic category (which is exactly what I want), but does the same thing for the other variable (x1) as well. I would like to calculate the average value of x1 over years and isic categories, i.e. value of x1 to not depend on isic. One way around is just using -collapse- over new2, and then have it merged with another dataset containing the average of x1. Interestingly, the average of x1 for ccode == "ARG" should be 2.319444 = (2.0416667 + 2.4166667 + 2.5)/3, but the following code:
gives the average for x1 as 2.3385417. Any observations and help on the above questions will be greatly appreciated.
Best regards,
Suryadipta.
I am using Stata for Windows 12.1. I have created new1 and new2 in the attached dataset using the following commands:
Code:
bysort ccode isic: egen new1 = sum(y)
Code:
bysort ccode isic year: egen new2 = sum(y)
I would like to create the average values of y for each isic category over the years, as well as the average of x1. However, the following code:
Code:
collapse (mean) new2 x1, by(ccode isic)
Code:
collapse (mean) x1, by(ccode)
Best regards,
Suryadipta.
Comment