I have data in long format. See below example.
I want to select the first observation of the variable "days" for each id where days<=300 & percent<=10 & non missing. For subjects that do not have that condition I want 0 (e.g. subject 2).
Just like the "wanted" variable, where wanted = 1 for days<=300 & non missing & Percent<=10, for the first observation per id.
Which code do I run for the whole dataset? Please help. Thanks in advance.
@Leonardo Guizzetti can you please help with this example? This is is clearer example. Thank you.
I want to select the first observation of the variable "days" for each id where days<=300 & percent<=10 & non missing. For subjects that do not have that condition I want 0 (e.g. subject 2).
Just like the "wanted" variable, where wanted = 1 for days<=300 & non missing & Percent<=10, for the first observation per id.
Which code do I run for the whole dataset? Please help. Thanks in advance.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte id int days float Percent byte wanted 1 50 9 1 1 100 8 . 1 500 12 . 2 2000 4 0 2 4000 40 . 2 6000 .7 . 3 100 5 1 3 150 4 . 4 . . . 4 200 .1 0 end

Comment