The dataset is listed below, and I want to delete the data after the first occurrence of 1 in the variable "employment" within ID. Also, I want to create a new variable "time", which should be the total number of "1" or "0" after the deletion within ID. Can someone help with Stata code?
Thank you!
* Example generated by -dataex-. For more info, type help dataex
clear
input byte (id employment)
1 1
1 1
1 1
1 0
1 0
1 0
1 0
1 0
1 1
2 0
2 0
2 0
2 0
2 0
3 1
3 1
3 1
3 1
3 1
3 1
3 1
4 1
4 0
4 0
4 0
4 1
4 1
end
Thank you!
* Example generated by -dataex-. For more info, type help dataex
clear
input byte (id employment)
1 1
1 1
1 1
1 0
1 0
1 0
1 0
1 0
1 1
2 0
2 0
2 0
2 0
2 0
3 1
3 1
3 1
3 1
3 1
3 1
3 1
4 1
4 0
4 0
4 0
4 1
4 1
end
Comment