Hello Everyone,
I use Stata 15.
The table below shows customer ID, year, and the value of transactions each customer did with two brands (brand1, and brand2).
I need to calculate the total value of transactions each customer did with each brand in each two consecutive years starting in 1990 (i.e., 1990-1991, 1992-1993, 1994-1995, and so on). That said, transactions in year 1991 should not be added to transactions in year 1992.
Then, I need to calculate the difference between the total transactions with brand1 and brand2, for each two consecutive years, for each customer (for example, transactions with brand1 in 1990-1991 minus transactions with brand2 in 1990-1991)
Thank you very much for your help.
id year brand1 brand2
1 1989 400 0
1 1990 100 50
1 1990 100 0
1 1991 100 0
1 2001 100 0
2 2000 250 0
2 2000 0 300
2 2000 0 690
2 2001 0 230
3 2009 890 0
3 2010 200 0
3 2011 0 2000
4 2013 120 0
4 2015 450 0
4 2015 400 230
4 2015 450 1200
4 2016 110 0
Related Posts with sum of specific consecutive obs
Mann-Kendall trend test in STATA (Tutorials)Hello Everyone, I am trying to find out how to do a non-parametric Mann-Kendall trend test to detec…
Difference in Differences with unbalanced (asymmetric) time periodsHello list, I am troubled by a problem I face in my thesis: In a difference-in-differences approach…
Line Plots -- Proportion and Average with condition Code: +---------------------------------------------------------------------------------------…
Multiple imputationHello, I am analysing a dataset to recreate a prognostic score. Three of the 10 variables that go i…
Multinominal logit model, IIADear all, I tray to analyze the determinants of loan repayment performance in a given organization. …
Subscribe to:
Post Comments (Atom)
0 Response to sum of specific consecutive obs
Post a Comment