(no subject)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

(no subject)

Hartman, Lacey (MDH)

I need to assign a dummy variable equal to 1 until a weighted proportion for a subset of cases reaches a certain cutoff.  So, for example, I want to assign records as SI=1 until the proportion of (sum of weights where SI=1 for a given class)/(sum of weights for all records in a given class)=0.13.

 

 

I have already used the aggregate function to assign the sum of weights to each record depending on what class they are in, but I’m trying to figure out a way to use a loop statement to create the numerator that I need above so that the loop knows when to stop.  But it doesn’t seem that aggregate works within the LOOP END LOOP function, I tried this code:

 

loop if (indic=1 & sizemore1=1 & prop1<.0875).

compute si=1.

aggregate

/break si

/sumnum1=sum(perwt06f).

do if si=1.

compute prop1=sumnum1/sumwt1.

end if.

end loop.

 

Would appreciate any advice about a better approach.

 

Thanks!

 

Reply | Threaded
Open this post in threaded view
|

Re:

Peck, Jon

The CREATE command can construct a new variable whose values are the cumulative sums of another variable (CSUM).  You could do that and then just COMPUTE a 0/1 variable from that.

 

HTH,

Jon Peck

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Hartman, Lacey (MDH)
Sent: Wednesday, October 21, 2009 3:46 PM
To: [hidden email]
Subject: [SPSSX-L]

 

I need to assign a dummy variable equal to 1 until a weighted proportion for a subset of cases reaches a certain cutoff.  So, for example, I want to assign records as SI=1 until the proportion of (sum of weights where SI=1 for a given class)/(sum of weights for all records in a given class)=0.13.

 

 

I have already used the aggregate function to assign the sum of weights to each record depending on what class they are in, but I’m trying to figure out a way to use a loop statement to create the numerator that I need above so that the loop knows when to stop.  But it doesn’t seem that aggregate works within the LOOP END LOOP function, I tried this code:

 

loop if (indic=1 & sizemore1=1 & prop1<.0875).

compute si=1.

aggregate

/break si

/sumnum1=sum(perwt06f).

do if si=1.

compute prop1=sumnum1/sumwt1.

end if.

end loop.

 

Would appreciate any advice about a better approach.

 

Thanks!

 

Reply | Threaded
Open this post in threaded view
|

(no subject)

Maguin, Eugene
In reply to this post by Hartman, Lacey (MDH)
Lacey,

I'd like to offer a reply but please bear in mind that I also don't quite
understand what you are doing.

It sounds like like you have a variable ('group') that defines groups of
cases. All cases in each group gets the same weight. Call this variable
'wate'. Cases having different values for group might have different values
of wate. I'm guessing that you have a procedure for defining the weight for
each value of group.

What you want to do is assign a value of 1 to a variable, call it 'pick',
provided that the cumulative sum of wate is less than some predefined value,
call this variable 'cutoff', that you have already defined. Let's assume
that's true. So, in some of the groups, a fraction of the possible cases
will be marked, i.e., pick=1; however, in other groups all possible cases
may be marked. So, I'll also assume that the case order does not need to be
randomized.

This is untested but it is what I'd start with.

Sort cases by group id.

Compute cum=0.
Compute pick=0.
Do if ($casenum eq 1).
+  compute cum=wate.
+  compute pick=1.
Else if (group eq lag(group)).
+  compute cum=lag(cum)+wate.
+  if (cum le cutoff) pick=1.
Else.
+  compute cum=wate.
+  compute pick=1.
End if.


Gene Maguin

>>I need to assign a dummy variable equal to 1 until a weighted proportion
for a subset of cases reaches a certain cutoff.  So, for example, I want to
assign records as SI=1 until the proportion of (sum of weights where SI=1
for a given class)/(sum of weights for all records in a given class)=0.13.

I have already used the aggregate function to assign the sum of weights to
each record depending on what class they are in, but I'm trying to figure
out a way to use a loop statement to create the numerator that I need above
so that the loop knows when to stop.  But it doesn't seem that aggregate
works within the LOOP END LOOP function, I tried this code:

loop if (indic=1 & sizemore1=1 & prop1<.0875).
compute si=1.
Aggregate /break si/sumnum1=sum(perwt06f).
do if si=1.
compute prop1=sumnum1/sumwt1.
end if.
end loop.

Would appreciate any advice about a better approach.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

(no subject)

Hartman, Lacey (MDH)
Thanks Gene--I think I have found a solution, my apologies if my explanation was unclear, I really appreciate your response.  It looks like my problem can be solved by using the SPLIT FILE and CREATE statements.

Thanks again!
Lacey

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gene Maguin
Sent: Thursday, October 22, 2009 3:13 PM
To: [hidden email]
Subject:

Lacey,

I'd like to offer a reply but please bear in mind that I also don't quite
understand what you are doing.

It sounds like like you have a variable ('group') that defines groups of
cases. All cases in each group gets the same weight. Call this variable
'wate'. Cases having different values for group might have different values
of wate. I'm guessing that you have a procedure for defining the weight for
each value of group.

What you want to do is assign a value of 1 to a variable, call it 'pick',
provided that the cumulative sum of wate is less than some predefined value,
call this variable 'cutoff', that you have already defined. Let's assume
that's true. So, in some of the groups, a fraction of the possible cases
will be marked, i.e., pick=1; however, in other groups all possible cases
may be marked. So, I'll also assume that the case order does not need to be
randomized.

This is untested but it is what I'd start with.

Sort cases by group id.

Compute cum=0.
Compute pick=0.
Do if ($casenum eq 1).
+  compute cum=wate.
+  compute pick=1.
Else if (group eq lag(group)).
+  compute cum=lag(cum)+wate.
+  if (cum le cutoff) pick=1.
Else.
+  compute cum=wate.
+  compute pick=1.
End if.


Gene Maguin

>>I need to assign a dummy variable equal to 1 until a weighted proportion
for a subset of cases reaches a certain cutoff.  So, for example, I want to
assign records as SI=1 until the proportion of (sum of weights where SI=1
for a given class)/(sum of weights for all records in a given class)=0.13.

I have already used the aggregate function to assign the sum of weights to
each record depending on what class they are in, but I'm trying to figure
out a way to use a loop statement to create the numerator that I need above
so that the loop knows when to stop.  But it doesn't seem that aggregate
works within the LOOP END LOOP function, I tried this code:

loop if (indic=1 & sizemore1=1 & prop1<.0875).
compute si=1.
Aggregate /break si/sumnum1=sum(perwt06f).
do if si=1.
compute prop1=sumnum1/sumwt1.
end if.
end loop.

Would appreciate any advice about a better approach.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD