I use Stata 13.1 and I couldn't get the results I want.
I want to sum up all values in the third column 'expgrp_total' by year and create a new variable filled with the summed value for that same year across the rows.
My command is this:
bysort round_year ( firm_id_new) : gen ind_patsubgrp_total = sum( expgrp_total)
I was expecting in the 4th column to have the total value 75 for all 1978 rows, and 144 for all 1979 rows.
Please let me know what I can do to change. Thank you.
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(round_year firm_id_new) float(expgrp_total ind_patsubgrp_total)
1978 68 0 0
1978 89 0 0
1978 130 22 22
1978 181 53 75
1978 182 0 75
1978 201 0 75
1979 12 0 0
1979 68 1 1
1979 86 63 64
1979 89 0 64
1979 97 0 64
1979 107 0 64
1979 113 0 64
1979 130 33 97
1979 181 47 144
1979 182 0 144
1979 201 0 144
1980 12 0 0
1980 54 0 0
1980 62 1 1
1980 67 0 1
1980 68 0 1
1980 82 43 44
1980 86 39 83
1980 89 0 83
1980 96 0 83
1980 97 0 83
I want to sum up all values in the third column 'expgrp_total' by year and create a new variable filled with the summed value for that same year across the rows.
My command is this:
bysort round_year ( firm_id_new) : gen ind_patsubgrp_total = sum( expgrp_total)
I was expecting in the 4th column to have the total value 75 for all 1978 rows, and 144 for all 1979 rows.
Please let me know what I can do to change. Thank you.
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(round_year firm_id_new) float(expgrp_total ind_patsubgrp_total)
1978 68 0 0
1978 89 0 0
1978 130 22 22
1978 181 53 75
1978 182 0 75
1978 201 0 75
1979 12 0 0
1979 68 1 1
1979 86 63 64
1979 89 0 64
1979 97 0 64
1979 107 0 64
1979 113 0 64
1979 130 33 97
1979 181 47 144
1979 182 0 144
1979 201 0 144
1980 12 0 0
1980 54 0 0
1980 62 1 1
1980 67 0 1
1980 68 0 1
1980 82 43 44
1980 86 39 83
1980 89 0 83
1980 96 0 83
1980 97 0 83
Comment