I have the following dataset in a long format with 6 records per patient_id corresponding to 3 timepoints and 2 jaws:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int patient_id byte timepoint long(jaw retainer) double irreg_index 1 1 2 1 4.2 1 1 1 2 . 1 2 2 1 1.71 1 2 1 2 .97 1 3 2 1 .58 1 3 1 2 .22 3 1 1 3 1.18 3 1 2 1 9.83 3 2 2 1 .66 3 2 1 3 .85 3 3 1 3 .51 3 3 2 1 .98 end
I have tried to reshape my data wide in order to generate the difference :
. gen id=_n
. reshape wide irreg_index ,i( id) j(timepoint)
(note: j = 1 2 3)
Data long -> wide
-----------------------------------------------------------------------------
Number of obs. 450 -> 450
Number of variables 6 -> 7
j variable (3 values) timepoint -> (dropped)
xij variables:
irreg_index -> irreg_index1 irreg_index2 irreg_index3
-----------------------------------------------------------------------------
but as the number of rows is maintained I get many empty cells and I cannot calculate the difference as further data manipulation is needed.
Any advice would be appreciated.
Thank you,
Nikos
0 Response to Calculate difference of an outcome variable between timepoints
Post a Comment