I have a panel dataset as below and I want to calculate the average:
I want to calculate the average of FAT_w1 for each year 2016,2017,2018,2019,2020,2021 for each of group treat1=1 and treat1=0.
For the dataset above, the results should be:
Average for treat1=1 and year1=2016 is .
Average for treat1=1 and year1=2017 is 9.328
Average for treat1=1 and year1=2018 is 8.183
...
...
Average for treat1=1 and year1=2021 is 7.4
Average for treat1=0 and year1=2016 is .
Average for treat1=0 and year1=2017 is 0.682
...
Average for treat1=0 and year1=2021 is 1.464
Many thanks and best regards.
Code:
clear input float year1 long TYPE2 float(treat1 FAT_w1 post33 post33treat1) 2016 2 0 . 0 0 2016 3 . . 0 . 2017 3 . 105.86112 0 . 2018 3 . 169.16325 0 . 2021 3 . . 1 . 2019 4 1 . 1 1 2020 4 1 6.876883 1 1 2017 6 1 . 0 0 2018 6 1 2.2230647 0 0 2019 6 1 2.0798314 1 1 2020 6 1 1.665593 1 1 2021 6 1 1.4405484 1 1 2016 7 1 . 0 0 2017 7 1 9.328573 0 0 2018 7 1 14.143867 0 0 2019 7 1 16.777643 1 1 2020 7 1 19.836254 1 1 2021 7 1 13.363945 1 1 2016 10 0 . 0 0 2019 10 0 . 1 0 2020 10 0 10.358336 1 0 2016 11 0 . 0 0 2017 11 0 .6820889 0 0 2018 11 0 .8348646 0 0 2019 11 0 1.1720647 1 0 2020 11 0 1.3943592 1 0 2021 11 0 1.464206 1 0 2017 13 0 . 0 0 2018 13 0 14.170573 0 0 2019 13 0 17.122456 1 0 2020 13 0 10.125214 1 0 end label values TYPE2 TYPE2 label def TYPE2 2 "2557XG", modify label def TYPE2 3 "2563UY", modify label def TYPE2 4 "2563UZ", modify label def TYPE2 6 "2580PG", modify label def TYPE2 7 "25846A", modify label def TYPE2 10 "2621N5", modify label def TYPE2 11 "2622UU", modify label def TYPE2 13 "2625KH", modify
For the dataset above, the results should be:
Average for treat1=1 and year1=2016 is .
Average for treat1=1 and year1=2017 is 9.328
Average for treat1=1 and year1=2018 is 8.183
...
...
Average for treat1=1 and year1=2021 is 7.4
Average for treat1=0 and year1=2016 is .
Average for treat1=0 and year1=2017 is 0.682
...
Average for treat1=0 and year1=2021 is 1.464
Many thanks and best regards.

Comment