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.
negative and insignificant Error correction coefficienti am working on panel data( (21) cross section data 1990-2019) dealing with symmetric and asymmetric…
Help!Can't open data in STATADear Statalister, I would like to ask why I cannot open data that download as STATA v14+ file.dta f…
How can I 'find' a specific word across multiple variable strings?I'm using Stata 14.2 on Windows. I have a dataset which is STI testing data, each line is a test res…
egen with conditionsDear Stata Forum, I have a panel data with several groups. Year and ID with three variables : varia…
Add local variable string to a string to call global variable in a loopHi, I am experiencing a syntax problem. I would like to call a global variable base on a string cre…
Subscribe to:
Post Comments (Atom)
0 Response to How to match questionnaire updates with the shortest interval to a fixed date.
Post a Comment