Hello, I want to find whether the variable has remained unchanged for more than 3 months and generate a binary variable A, (if remained: A == 1, if not: A == 1)
My data contains more than 40,000 unique IDs and more than 1,000,000 observations, so it was hard to find a good way to make the variable I wanted.
The below table includes each case I want to handle, and in the real dataset, it is much bigger.
ID, condition, and date are the variables I have in my dataset, and variable A is the result I want.
Also, the date variable is already in Stata format.
I have been struggling with this question for days, so would you please help me get the result I want with handling those specific cases?
(I've tried to solve it with a complicated loop, but it was not working cause my data was too big)
Thanks.
My data contains more than 40,000 unique IDs and more than 1,000,000 observations, so it was hard to find a good way to make the variable I wanted.
The below table includes each case I want to handle, and in the real dataset, it is much bigger.
ID | condition | date | A |
111 | 1 | 01Jan13 | 1 |
111 | 1 | 05May13 | 1 |
111 | 1 | 20Jun13 | 1 |
111 | 0 | 01Dec14 | 0 |
222 | 0 | 03Jan15 | 0 |
222 | 1 | 05May15 | 0 |
222 | 0 | 29May15 | 0 |
222 | 1 | 30Jun15 | 0 |
333 | 0 | 01Jan08 | 0 |
333 | 1 | 05Dec09 | 1 |
333 | 1 | 31Jun09 | 1 |
333 | 1 | 01Oct09 | 1 |
444 | 0 | 03Jul06 | 0 |
444 | 1 | 06Jan07 | 1 |
444 | 1 | 03Jun11 | 1 |
555 | 0 | 06Jan19 | 0 |
555 | 1 | 05Sep21 | 0 |
555 | 1 | 15Sep21 | 0 |
555 | 1 | 16Sep21 | 0 |
666 | 0 | 17Jan11 | 0 |
666 | 1 | 05May12 | 1 |
666 | 1 | 16May12 | 1 |
666 | 1 | 19Dec12 | 1 |
666 | 1 | 21Dec13 | 1 |
Also, the date variable is already in Stata format.
I have been struggling with this question for days, so would you please help me get the result I want with handling those specific cases?
(I've tried to solve it with a complicated loop, but it was not working cause my data was too big)
Thanks.
Comment