Dear Stata users,
I would need help with finding the first time a specific value or greater in a varlist appears.
I have panel data looking soemthing like this:
ID NR VAR
1 1 15
1 2 3
1 3 22
1 4 17
1 5 25
I would like to mark the observation where var is 20 or greater for the first time, by each id. In the case above it's the third observtion. It might also be that for some IDs the value 20 or greater doesn't exist. As I understand the egen command ifirst is used to find a specific value only, and cannot be combined with ( >= ).
So I tried the command:
egen ig20= ifirst(var), v(>=20) after by(ID)
"option value () invalid" is the error syntax, which of course has to do with the >=. Executing the code without >= works perfectly fine.
Would you know how I could proceed instead?
Best and thanks in advance,
Ida
I would need help with finding the first time a specific value or greater in a varlist appears.
I have panel data looking soemthing like this:
ID NR VAR
1 1 15
1 2 3
1 3 22
1 4 17
1 5 25
I would like to mark the observation where var is 20 or greater for the first time, by each id. In the case above it's the third observtion. It might also be that for some IDs the value 20 or greater doesn't exist. As I understand the egen command ifirst is used to find a specific value only, and cannot be combined with ( >= ).
So I tried the command:
egen ig20= ifirst(var), v(>=20) after by(ID)
"option value () invalid" is the error syntax, which of course has to do with the >=. Executing the code without >= works perfectly fine.
Would you know how I could proceed instead?
Best and thanks in advance,
Ida
Comment