I have a longitudinal survey data where each row represents an interview date with a given individual, and different individuals were interviewed across different dates in the survey, as shown in the data example below.
[CODE]
dataex id date
----------------------- copy starting from the next line -----------------------
I am trying to create an indicator measured at the individual-level for the first interview date relative to the start date of our dataset, which begins on 24jun2011.
Therefore, I have tried computing this indicator per individual using the guidance here, as follows:
However, this computes the number of days for each row/interview date, rather than per individual. Is it possible to create one unique first_interview per individual?
For instance, if the survey starts on 24jun2011 and individual A is first interviewed on 28jun2011, then the value for "first_interview" should be 4 days for person A.
Here is a data example of the newly created variable "first_interview"
[CODE]
dataex id date first_interview
----------------------- copy starting from the next line -----------------------
[CODE]
dataex id date
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float id int date 1 19025 2 18968 3 19219 4 19241 4 19243 5 19049 6 19013 6 19150 6 19153 6 19166 6 19167 6 19169 6 19172 6 19174 6 19181 6 19185 7 18975 7 18977 7 18984 7 18995 7 19000 7 19004 7 19008 7 19009 7 19013 7 19021 8 18987 8 18989
I am trying to create an indicator measured at the individual-level for the first interview date relative to the start date of our dataset, which begins on 24jun2011.
Therefore, I have tried computing this indicator per individual using the guidance here, as follows:
Code:
by id: gen first_interview = date - date("24/06/2011", "DMY")
For instance, if the survey starts on 24jun2011 and individual A is first interviewed on 28jun2011, then the value for "first_interview" should be 4 days for person A.
Here is a data example of the newly created variable "first_interview"
[CODE]
dataex id date first_interview
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float id int date float join 1 19025 223 2 18968 166 3 19219 417 4 19241 439 4 19243 441 5 19049 247 6 19013 211 6 19150 348 6 19153 351 6 19166 364 6 19166 364 6 19167 365 6 19169 367

Comment