Hi everyone,
I have a data looks as below:
I need to calculate two variables based on the data that I have: past_purchase_avg is the average purchase amount for each consumer in all the previous periods and the aggregate purchase amount is the summation of all the previous purchases amounts for each consumer. I got stuck here and I wonder if anyone knows how to realize this in stata.
Thanks a lot!
I have a data looks as below:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte consumer str9 date int purchaseamount byte(past_purchase_avg past_purchcase_agg) 1 "2020/8/24" 300 . . 1 "2020/8/25" 400 . . 1 "2020/8/26" 600 . . 1 "2020/8/27" 700 . . 1 "2020/8/28" 900 . . 1 "2020/8/29" 1000 . . 1 "2020/8/30" 200 . . 2 "2020/8/28" 2000 . . 2 "2020/8/29" 21 . . 2 "2020/8/30" 300 . . end
Thanks a lot!
Comment