Calculate Discount Factor and Add Into Syntax

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

Calculate Discount Factor and Add Into Syntax

Eric Black
I have to add a discount factor for a variable in certain cases which is
based on an average ratio.  For example, if I had two variables M1 and M2, I
would take M2 *if M2 is available*.  If not, I would take M1, but I would
discount it by factor D.  D is the average of M2/M1.


I am not sure if I can parse this ratio in or whether I need to first
calculate the ratio and then more or less manually enter it into my syntax file.

Any advice is greatly appreciated.

Matt

=====================
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
|

Re: Calculate Discount Factor and Add Into Syntax

Bruce Weaver
Administrator
Something like this?

COMPUTE M2overM1 = M2/M1.

* Use AGGREGATE to get D, the mean of M2overM1, writing it to the current data set.
* Generate syntax via the GUI, or look it up in the FM.

DO IF not missing(M2).
- COMPUTE NewVar = M2.
ELSE.
- COMPUTE NewVar = { some expression involving M1 and D -- I'm not exactly sure what you mean }.
END IF.


matti wrote
I have to add a discount factor for a variable in certain cases which is
based on an average ratio.  For example, if I had two variables M1 and M2, I
would take M2 *if M2 is available*.  If not, I would take M1, but I would
discount it by factor D.  D is the average of M2/M1.


I am not sure if I can parse this ratio in or whether I need to first
calculate the ratio and then more or less manually enter it into my syntax file.

Any advice is greatly appreciated.

Matt

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Calculate Discount Factor and Add Into Syntax

Eric Black
In reply to this post by Eric Black
Thanks Bruce.

My problem with the FM is that I don't know where TH to look for in the FM ;)

I need to do it multiple times, in a simple but long drawn version, it is:
compute discount2 = M1/M2.
compute discount3 = M1/M3.
compute discount4 = M1/M4.

if sysmis(M1) M1 = M2*discount2.
exe.
if sysmis(M1) M1 = M3*discount3.
exe.
if sysmis(M1) M1 = M4*discount4.
exe.


Aggregate is only slightly more elegant than a simple mean table and then
using Excel to add the discount constants.  I wasn't sure if there is an
elegant way of taking the results for discount2-4 directly within the syntax
file (I believe Stata allows that and I was hoping SPSS does so too)

Matt

=====================
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
|

Re: Calculate Discount Factor and Add Into Syntax

Bruce Weaver
Administrator
Matt, it would help greatly if you provided a small sample data set (via DATA LIST) that shows what the data looks like initially, and what you want it to look like afterwards.  (It would help me, at least.)  ;-)


matti wrote
Thanks Bruce.

My problem with the FM is that I don't know where TH to look for in the FM ;)

I need to do it multiple times, in a simple but long drawn version, it is:
compute discount2 = M1/M2.
compute discount3 = M1/M3.
compute discount4 = M1/M4.

if sysmis(M1) M1 = M2*discount2.
exe.
if sysmis(M1) M1 = M3*discount3.
exe.
if sysmis(M1) M1 = M4*discount4.
exe.


Aggregate is only slightly more elegant than a simple mean table and then
using Excel to add the discount constants.  I wasn't sure if there is an
elegant way of taking the results for discount2-4 directly within the syntax
file (I believe Stata allows that and I was hoping SPSS does so too)

Matt

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Calculate Discount Factor and Add Into Syntax

Eric Black
In reply to this post by Eric Black
Below is a simplified example

data list list (",")/ id M1 to M4 (5f5.0).
begin data
1,1,2,3,4
2,2,3,2,3
3,,2, 2, 2
4,,,3, 3
end data.

compute discount2 = M1/M2.
compute discount3 = M1/M3.
compute discount4 = M1/M4.


mean tables discount2 to discount4/cell mean.

*This is the part where I would want the values of .5833 etc. to be added
automatically and not via the mean tables command.


if sysmis(M1) M1 = M2*.5833.
exe.
if sysmis(M1) M1 = M3*.6667.
exe.
if sysmis(M1) M1 = M4*.4583.
exe.

=====================
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
|

Re: Calculate Discount Factor and Add Into Syntax

David Marso
Administrator
In reply to this post by Eric Black
If M1 is missing the *ALL* of your 'discount' variables will be missing.
You need to provide a SPECIFIC example of initial state and desired state of the data.

matti wrote
Thanks Bruce.

My problem with the FM is that I don't know where TH to look for in the FM ;)

I need to do it multiple times, in a simple but long drawn version, it is:
compute discount2 = M1/M2.
compute discount3 = M1/M3.
compute discount4 = M1/M4.

if sysmis(M1) M1 = M2*discount2.
exe.
if sysmis(M1) M1 = M3*discount3.
exe.
if sysmis(M1) M1 = M4*discount4.
exe.


Aggregate is only slightly more elegant than a simple mean table and then
using Excel to add the discount constants.  I wasn't sure if there is an
elegant way of taking the results for discount2-4 directly within the syntax
file (I believe Stata allows that and I was hoping SPSS does so too)

Matt

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Calculate Discount Factor and Add Into Syntax

David Marso
Administrator
In reply to this post by Eric Black
"Aggregate is only slightly more elegant than a simple mean table "
I beg to differ!!! Please review the AGGREGATE command in the FM prior to making such statements!
Hint: MODE=ADDVARIABLES is your friend!
--
matti wrote
Thanks Bruce.

My problem with the FM is that I don't know where TH to look for in the FM ;)

I need to do it multiple times, in a simple but long drawn version, it is:
compute discount2 = M1/M2.
compute discount3 = M1/M3.
compute discount4 = M1/M4.

if sysmis(M1) M1 = M2*discount2.
exe.
if sysmis(M1) M1 = M3*discount3.
exe.
if sysmis(M1) M1 = M4*discount4.
exe.


Aggregate is only slightly more elegant than a simple mean table and then
using Excel to add the discount constants.  I wasn't sure if there is an
elegant way of taking the results for discount2-4 directly within the syntax
file (I believe Stata allows that and I was hoping SPSS does so too)

Matt

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Calculate Discount Factor and Add Into Syntax

Art Kendall
In reply to this post by Eric Black
open a new instance of SPSS.
copy and paste the syntax below into a new syntax window and print it.

This seems to be what you are asking for but does not quite make sense.
By the way if you have a set of computes with the same variable on the left as in your post each will over write the previous one so that you only need that last one.

Please repost your data example with more field(s) called  something like want1.
Art Kendall
Social Research Consultants

data list list (",")/ id M1 to M4 (5f5.0).
begin data
1,1,2,3,4
2,2,3,2,3
3,,2, 2, 2
4,,,3, 3
end data.
compute nobreak=1.
aggregate outfile=* mode = addvariables /break = nobreak
/ discount2 to discount4 = mean(m2 to m4).
formats discount2 to discount4(f6.4).
do if sysmis(m1).
compute newm1 = m4* discount4.
ELSE.
compute newm1 = m1.
end if.
formats newm1 (f6.4).
list.

On 4/16/2012 2:55 PM, Matt Kretschmer wrote:
Thanks Bruce.

My problem with the FM is that I don't know where TH to look for in the FM ;)

I need to do it multiple times, in a simple but long drawn version, it is:
compute discount2 = M1/M2.
compute discount3 = M1/M3.
compute discount4 = M1/M4.

if sysmis(M1) M1 = M2*discount2.
exe.
if sysmis(M1) M1 = M3*discount3.
exe.
if sysmis(M1) M1 = M4*discount4.
exe.


Aggregate is only slightly more elegant than a simple mean table and then
using Excel to add the discount constants.  I wasn't sure if there is an
elegant way of taking the results for discount2-4 directly within the syntax
file (I believe Stata allows that and I was hoping SPSS does so too)

Matt

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Calculate Discount Factor and Add Into Syntax

Bruce Weaver
Administrator
In reply to this post by Eric Black
After your DATA LIST command:

DO REPEAT d = d2 to d4 / m = m2 to m4.
- COMPUTE d = M1 / m .
END REPEAT.

AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=
  /discount2 to discount4 = MEAN(d2 to d4) .

DO REPEAT d = discount2 to discount4 / m = m2 to m4.
- IF SYSMIS(M1) M1 = m*d.
END REPEAT.
formats m1 to m4 (f5.3).
LIST id to m4.

If the number of terms is quite large, you might want to use VECTOR and LOOP rather than DO-REPEAT so that you can exit the loop as soon as SYSMIS(M1) is no longer true.  See LOOP-END LOOP in the FM.

HTH.

matti wrote
Below is a simplified example

data list list (",")/ id M1 to M4 (5f5.0).
begin data
1,1,2,3,4
2,2,3,2,3
3,,2, 2, 2
4,,,3, 3
end data.

compute discount2 = M1/M2.
compute discount3 = M1/M3.
compute discount4 = M1/M4.


mean tables discount2 to discount4/cell mean.

*This is the part where I would want the values of .5833 etc. to be added
automatically and not via the mean tables command.


if sysmis(M1) M1 = M2*.5833.
exe.
if sysmis(M1) M1 = M3*.6667.
exe.
if sysmis(M1) M1 = M4*.4583.
exe.

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).