Dear Statalist,
I just want to check if this is ok or if there is a more elegant way to tidy up a messy dataset. Stata IC15 user.
Each person has a questionnaire they can update whenever they want. I am trying to find the closest questionnaire update to a target date that is different for each patient
I first reshaped wide so one line per patient and found there were up to 17 updates of the questionnaires per person, some with only 1 update.
I gen a dummy interval (interval) = 10,000 days and then a variable (closest_update) for the right questionnaire update =- -9
I then calculate the interval between each questionnaire update and the target date
then replace the interval with the observed interval for 0/17 if it is less than the previous value and use that to replace the value of the closest_value
interval = 100000
gen correct_update = -9
forvalues i = 0/17 {
gen interval`i' = abs(target_date- date_of_update`i') if date_of_update`i'~=.
replace closest_update = `i' if abs(interval`i') < interval
replace interval = interval`i' if closest_version ==`i'
}
Also is there a way to adapt this to find the closest pair of 2 questionnaires that are updated at different times rather than a fixed date per patient. Would I need to generate the interval between each update of questionnaire a with each version of questionnaire b and then sort them?
Hope this makes sense.
Kassim
Related Posts with How to match questionnaire updates with the shortest interval to a fixed date.
Rearranging individual dates within a varlistHi, I'm extremely new to Stata (5 weeks) and am stuck with something my lecturer has asked us to do.…
Unlimited loop of events tested when using eventstudy2Hello! I am currently conducting my final thesis and for that I am using the package eventstudy2, a…
Request syntax assistance with v17 [table] command to get table of frequency in descending frequency orderI apologize for even asking, assuming there is something very simple I simply cannot find. As [tabl…
Making not to show the each results in the tableHello, Thank you so much for your help in advance. I see my result of table as below, but to put it…
Statistical hypotheses test for independent count data and dependent continous variablesDear Stata Community, I am looking for the right statistical model to test hypotheses with the foll…
Subscribe to:
Post Comments (Atom)
0 Response to How to match questionnaire updates with the shortest interval to a fixed date.
Post a Comment