Question

I have a file with repeated measures data and another file with single observations for the same persons (e.g. in one file subjects have repeated assessments and the other file just says if subjects are male or female) when I merge the files I get something like this:

ID time gender     
1 1 0  
1 2  
1 3  
2 1 1  
2 2  
3 1 0  
3 2  
3 3  
3 4  

but I want that the variable that was measured once (e.g.male/female) to be repeated across time (in each row) for each subject. So I would like to have :

1 1 0  
1 2 0  
1 3 0   
2 1 1  
2 2 1

and not do it manually, since I have thousands of cases... How to do this in SPSS (preferably), or in R ?

Was it helpful?

Solution

You should have used match files with one "file" (multiple record per ID) and one "table" (no duplicate ID's).

But you can probably still fix it by running

sort cases by ID.
if mis(gender) and ID = lag(ID) gender= lag(gender).

Wherever there's no value for gender, it will be filled in with the gender of the previous case if it has the same ID as the current one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top