It is my first post here and I hope it is not a question that is too trivial. Unfortunately I have not found any old posts concerning this issue.
I have panel data with over 160'000 obsevations and around 1'500 variables (unbalanced).
Now I would like to create the variable "length" which measures the length of unemployment.
This is how it should be constructed: every occurence of 1s in "unemployed" needs to be summed up. This value then needs to be associated to the new variable "length". It needs to take this value for the first obervation of the occurrence we are summing up. "Length" is the variable I need to create.
I have so far tried some commands with: bysort and sum/count. Unfortunately without any success.
Can anyone give me advice on this? How would you solve it?
I hope this table shows even better what I am trying to do...
Thank you!
id | year | unemployed | length |
1 | 2000 | 0 | 0 |
1 | 2001 | 1 | 3 |
1 | 2002 | 1 | 0 |
1 | 2003 | 1 | 0 |
2 | 2000 | 1 | 1 |
2 | 2001 | 0 | 0 |
2 | 2002 | 1 | 2 |
2 | 2003 | 1 | 0 |
3 | 2000 | 0 | 0 |
3 | 2001 | 1 | 2 |
3 | 2002 | 1 | 0 |
0 Response to Create new variable with sums of occurrences
Post a Comment