I have data with a laboratory value on each line, and each STUDYID has with multiple laboratory values. I am trying to match the closest height (in time) to each individual laboratory value's date (each line). Each individual has between 2-200 heights and are in wide format.
i.e. the data looks like this:
STUDYID LBDTM ContactDate1 Height1 ContactDate2 Height2 ContactDate3 Height3... and so on.
I am trying to write a loop command to get the difference between each ContactDate and the LabDateTime (LBDTM)
I am writing a code like this:
foreach var of varlist `ContactDate*' {
gen HEIGHTDIFFERENCE= abs(LBDTM- `ContactDate*')
}
What am I doing wrong? I'm getting multiple errors, usually syntax.
Ideally, I would have multiple variables with the absolute value between each contact date and the laboratory date, then be able to identify the minimum value.
Thanks in advance for any help.
i.e. the data looks like this:
STUDYID LBDTM ContactDate1 Height1 ContactDate2 Height2 ContactDate3 Height3... and so on.
I am trying to write a loop command to get the difference between each ContactDate and the LabDateTime (LBDTM)
I am writing a code like this:
foreach var of varlist `ContactDate*' {
gen HEIGHTDIFFERENCE= abs(LBDTM- `ContactDate*')
}
What am I doing wrong? I'm getting multiple errors, usually syntax.
Ideally, I would have multiple variables with the absolute value between each contact date and the laboratory date, then be able to identify the minimum value.
Thanks in advance for any help.
Comment