I have a question about constructing count variable. Please refer to my sample data below.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str1 id int year str1 class byte cumulative_count "a" 2015 "A" 3 "a" 2015 "A" 3 "a" 2015 "B" 3 "a" 2015 "C" 3 "a" 2016 "A" 3 "a" 2016 "A" 3 "a" 2016 "B" 3 "a" 2017 "B" 4 "a" 2017 "D" 4 "a" 2018 "C" 5 "a" 2018 "E" 5 "b" 2015 "A" 1 "b" 2016 "B" 2 "b" 2017 "A" 2 "b" 2017 "B" 2 "b" 2018 "C" 3 end
For example, id "a" has three distinct alphabets "A, B, C" until 2015. So the value of "cumulative_count" in 2015 should be 3.
Until 2018, id "a" has five different alphabets "A, B, C, D, E". So the value of "cumulative_count" in 2018 should be 5.
Thanks a lot for any advice in advance.
0 Response to Counting distinct values cumulatively by group
Post a Comment