Hi,
I am a relatively inexperienced stata user and am hoping someone here might be able to help!
I am trying to merge dates from a cross-sectional dataset (this has around 1200 unique observations, each identified by a unique studyID) with a longitudinal dataset in which I have repeat observations (each observation is identified by studyID but in many cases studyID is used multiple times - every time more longitudinal data is collected studyID is entered with each new bit of longitudinal data being added as a row).
Both datasets are in long format and all participants in the longitudinal dataset are found in the cross-sectional dataset, but not all of those that are in the cross-sectional dataset are in the longitudinal dataset.
In the cross sectional dataset I have kept only the studyID and the 'dateattended' variable (which contains the date i need in DMY format) and i have called this 'studyIDanddateattended' (original i know!) and I have then sorted both datasets by studyID.
With the longitudinal dataset open as master, I have used the code:
merge m:1 studyID using studyIDanddateattended
However although this seems to merge on studyID, the new dateattended variable in the longitudinal dataset is not the same value as in the cross-sectional dataset, except for the first few observations.
I've tried lots of different ways of merging but can not seem to make it match up - if anyone has any advice i'd be very grateful.
Thanks so much, janey
I am a relatively inexperienced stata user and am hoping someone here might be able to help!
I am trying to merge dates from a cross-sectional dataset (this has around 1200 unique observations, each identified by a unique studyID) with a longitudinal dataset in which I have repeat observations (each observation is identified by studyID but in many cases studyID is used multiple times - every time more longitudinal data is collected studyID is entered with each new bit of longitudinal data being added as a row).
Both datasets are in long format and all participants in the longitudinal dataset are found in the cross-sectional dataset, but not all of those that are in the cross-sectional dataset are in the longitudinal dataset.
In the cross sectional dataset I have kept only the studyID and the 'dateattended' variable (which contains the date i need in DMY format) and i have called this 'studyIDanddateattended' (original i know!) and I have then sorted both datasets by studyID.
With the longitudinal dataset open as master, I have used the code:
merge m:1 studyID using studyIDanddateattended
However although this seems to merge on studyID, the new dateattended variable in the longitudinal dataset is not the same value as in the cross-sectional dataset, except for the first few observations.
I've tried lots of different ways of merging but can not seem to make it match up - if anyone has any advice i'd be very grateful.
Thanks so much, janey
Comment