Hello everyone, I have the following panel data set:
id | date | x1 | newvar |
1 | t=1 | 4 | 7 |
1 | t=2 | 7 | 21 |
1 | t=3 | 3 | 16 |
2 | t=1 | 1 | 7 |
2 | t=2 | 8 | 21 |
2 | t=3 | 10 | 16 |
3 | t=1 | 2 | 7 |
3 | t=2 | 6 | 21 |
3 | t=3 | 3 | 16 |
I would like to do create a new variable (newvar), which reflects the following:
For every date I would like to sum all values of x1 of the corresponding individuals (id).
I tried with loops but this would create a new variable for each single date with the respective value. I would prefer a one variable solution, due to the high number of dates in the sample.
Could someone please give me a solution, how to create a variable which sums across observations for a given date? Thank you very much in advance.
Kind regards, Katrin
Comment