Sequential numbering with repeated measures

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Mattias
Posts: 7
Joined: Thu Oct 13, 2011 7:58 am

Sequential numbering with repeated measures

Postby Mattias » Thu Dec 08, 2011 8:46 am

Hi,
I’m trying to create a ’SubID’ variable which sequentially numbers our respondents. We have a repeated measures design with multiple observations per respondent. The number of observations is not the same for each respondent. What we have is another variable numbering our households from which respondents come (‘HHschedule_no’), which is repeated for every household member for which we have observations. For each respondent we additionally have their ‘lineno’ which comes from our household roster, and since each respondent can have several observations, this ‘lineno’ is also repeated for each observation per respondent. Where I am stuck, is the fact that our variable ‘lineno’ of course is nested within our ‘HHschedule_no’ variable. Our data with the two variables looks like below, and we want our ‘SubID’ variable to take the same form as in the example data below.

Any help is greatly appreciated. Thank you in advance.
Mattias


Hhschedule_no lineno SubId
1 2 1
1 2 1
1 5 2
1 5 2
2 2 3
2 4 4
2 4 4
3 3 5
4 2 6
4 2 6
4 4 7
4 4 7
4 4 7
4 6 8
4 6 8
JonPedersen
Posts: 117
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: Sequential numbering with repeated measures

Postby JonPedersen » Thu Dec 08, 2011 4:35 pm

Hi,
several ways of doing this, but try:

Code: Select all

numeric NewSubID (F3.0).
leave NewSubID.
do if missing(lag(HHschedule_no)).
  compute NewSubID=1.
else.
  if (HHSchedule_no ne lag(HHschedule_no)) or (lineno ne lag(lineNo)) NewSubID=NewSubID+1.
end if.
exe.
hth,
jon
Mattias
Posts: 7
Joined: Thu Oct 13, 2011 7:58 am

Re: Sequential numbering with repeated measures

Postby Mattias » Mon Dec 12, 2011 9:51 am

Hi Jon,

This was exactly what I was trying to do. Thanks a lot!

Best,
Mattias
JonPedersen wrote:Hi,
several ways of doing this, but try:

Code: Select all

numeric NewSubID (F3.0).
leave NewSubID.
do if missing(lag(HHschedule_no)).
  compute NewSubID=1.
else.
  if (HHSchedule_no ne lag(HHschedule_no)) or (lineno ne lag(lineNo)) NewSubID=NewSubID+1.
end if.
exe.
hth,
jon

Who is online

Users browsing this forum: No registered users and 2 guests

cron