Hello,
The above code gives me the overall sum of variable A for each year (my dataset has 2 years). I want to create a new variable 'B' that equals (totalsum of year 1 / totalsum of year2). How can I do that?
How can we get the total sum of variable A for each year in a separate column as we can then calculate B easily? I have attached an example dataset below.
Thank you.
Code:
bysort year: egen totalsum = total(A), m
How can we get the total sum of variable A for each year in a separate column as we can then calculate B easily? I have attached an example dataset below.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(year a) 1 1 1 2 1 3 1 . 1 5 2 10 2 9 2 . 2 7 2 6 end
Comment