Recoding new sequence variable from continuous time variable

Welcome to the forum for MLwiN users. Feel free to post your question about MLwiN software here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Remember to check out our extensive software FAQs which may answer your question: http://www.bristol.ac.uk/cmm/software/s ... port-faqs/
Post Reply
jmarie03
Posts: 3
Joined: Tue Dec 10, 2019 11:30 am

Recoding new sequence variable from continuous time variable

Post by jmarie03 »

Hello all and thank you in advance for any advice.

I have a continuous time variable ('visdy', +/- 0, representing days from 'baseline' intake in a longitudinal study). Generally, participants were re-tested annually but there may be substantial variation of precise testing time.

I want to compute a 'occasion' variable (starting with 1) to categorize baseline and follow up visits. There is currently a 'sequence' variable that was supposed to represent this, but has many errors (approximately 10,000), becuase this database was formed from multiple studies that predated the primary one. So, for one participant (subjid001) you may have three 'sequence = 1' because they had 2 visits (visdy = -365, -650, for example) before the technical 'baseline visit' (visdy = 0), which were all entered as '1' in the initial databases.

Is there a way to recode a new variable based on the ascending values ('visdy') per participant ('subjidxx')?

Thank you very much!
ChrisCharlton
Posts: 1353
Joined: Mon Oct 19, 2009 10:34 am

Re: Recoding new sequence variable from continuous time variable

Post by ChrisCharlton »

I think that the following may do what you want:
  1. Sort your data by visdy within subjid. You can do this either via the Data Manipulation->Sort menu or via the SORT command. Note that this will only reorder the selected columns, so you need to include all the columns representing your data here.
  2. Generate a sequence for each block defined by subjid via the Data Manipulation->Multilevel data manipulation menu or via the MLSequence command.
  3. Optionally resort the data back into your preferred ordering.
jmarie03
Posts: 3
Joined: Tue Dec 10, 2019 11:30 am

Re: Recoding new sequence variable from continuous time variable

Post by jmarie03 »

Thanks very much for your reply. Apologies if I did not understand or follow your instructions correctly, but unfortunately this resulted in a continuous number of sequences for the new variable. What I am hoping to have happen is that within each subject (subjid), the time variable (visdy) to be sorted, and then the smallest value (whatever that is; it varies widely) to be assigned 1, the next smallest visdy = 2, and so on, per participant.
ChrisCharlton
Posts: 1353
Joined: Mon Oct 19, 2009 10:34 am

Re: Recoding new sequence variable from continuous time variable

Post by ChrisCharlton »

Did you set subjid as the variable under "On blocks defined by"? Doing this should restart the sequence back to one each time the value in this column changes.
jmarie03
Posts: 3
Joined: Tue Dec 10, 2019 11:30 am

Re: Recoding new sequence variable from continuous time variable

Post by jmarie03 »

I think I had it backwards! That worked out fantastic. Thank you so very much!! :D
Post Reply