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
Some queries about the latest sjlatexFellow Statalisters (especially StataCorp) I recently tried to update my version of sjlatex to the …
Standardization / z-transformation of matrixHi there, I want to standardize a large matrix (several 1000 rows and colums), so that it it has a m…
Time series techniiquesHi all, I try it again I have a dataset having as inputs: the id of products, quarters, Year corre…
Truncate a number to two decimalsHi, I have a doubt. I have a variable named "score" (float) as showed below and I want to truncate i…
Matching two samples by the same year/industry/provinceDear Stata experts, I have a sample of firms committed fraud. It has 1,700 observations. The format…
Subscribe to:
Post Comments (Atom)
0 Response to sum of specific consecutive obs
Post a Comment