Dear, good night!
See if anyone can give me a tip.
I consulted and I'm not finding topics on the subject.
I can't get out of the place.

Initial data
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input byte id int year byte d long value
 7 2013 0  515059
 7 2014 0  194830
 7 2015 0  -35234
 7 2016 1 -221832
 7 2017 1 -102977
 7 2018 0  171246
 7 2019 1  279258
 8 2016 0   20845
 8 2017 0   85152
 8 2018 1    2251
 8 2019 0   -9593
 9 2013 1  110555
 9 2014 0  112752
 9 2015 0  119663
 9 2016 0  116149
 9 2017 0  154470
 9 2018 0  142644
 9 2019 0  162139
10 2018 1 -223435
10 2019 1 -422415
11 2013 0   -1623
11 2014 0   -1035
11 2015 1      -5
11 2019 0    2113
12 2013 0    7678
12 2014 0    7075
12 2015 0    1245
12 2016 0  -39763
12 2017 0  -84226
12 2018 1 -133462
end
I'm trying to generate a group by id year, but truncating at the change from d 0 to 1
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input byte id int year byte d long value byte group long acum
 7 2013 0  515059  1  515059
 7 2014 0  194830  1  709889
 7 2015 0  -35234  1  674655
 7 2016 1 -221832  2 -221832
 7 2017 1 -102977  3 -102977
 7 2018 0  171246  3   68269
 7 2019 1  279258  4  279258
 8 2016 0   20845  5   20845
 8 2017 0   85152  5  105997
 8 2018 1    2251  6    2251
 8 2019 0   -9593  6   -7342
 9 2013 1  110555  7  110555
 9 2014 0  112752  7  223307
 9 2015 0  119663  7  342970
 9 2016 0  116149  7  459119
 9 2017 0  154470  7  613589
 9 2018 0  142644  7  756233
 9 2019 0  162139  7  918372
10 2018 1 -223435  8 -223435
10 2019 1 -422415  9 -422415
11 2013 0   -1623 10   -1623
11 2014 0   -1035 10   -2658
11 2015 1      -5 11      -5
11 2019 0    2113 11    2108
12 2013 0    7678 12    7678
12 2014 0    7075 12   14753
12 2015 0    1245 12   15998
12 2016 0  -39763 12  -23765
12 2017 0  -84226 12 -107991
12 2018 1 -133462 13 -133462
end
By group I'm trying to accumulate value by generating a new acum variable
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input byte id int year byte d long value byte group long acum
 7 2015 0  -35234  1  674655
 7 2016 1 -221832  2 -221832
 7 2018 0  171246  3   68269
 7 2019 1  279258  4  279258
 8 2017 0   85152  5  105997
 8 2019 0   -9593  6   -7342
 9 2019 0  162139  7  918372
10 2018 1 -223435  8 -223435
10 2019 1 -422415  9 -422415
11 2014 0   -1035 10   -2658
11 2019 0    2113 11    2108
12 2017 0  -84226 12 -107991
12 2018 1 -133462 13 -133462
end
Greetings