Hi,

I am working with firm-level data (cross-section data). I am trying to calculate the weighted sum of product Gross Value by (i) Product Code (given by productASICC) and (ii) State

I am using collapse command as follows:

(i) For Weighted Sum by Product Code
collapse (sum) sum_output=productGrossValue [aw=emult2] , by(productASICC)

(ii) For Weighted Sum by State

collapse (sum) sum_output=productGrossValue [aw=emult2], by(state)


However, when I collapse the two (separately) and then calculate the total of sum_output, I get a different answer in each case!

Total Sum (when doing (i))= 7956141480645.23

Total Sum (when doing(ii))=5334065631590.61


Please let me know if I am doing anything wrong! My gut is that, the two sums should be equal. But I dont know if my code is incorrect or not.

Thanks
Dhruv