Date: Wed, 9 Oct 2002 18:43:53 -0500 Reply-To: Carol Albright Sender: "SPSSX(r) Discussion" From: Carol Albright Subject: Re: syntax question-- repeating calculations' Comments: To: Student In-Reply-To: Content-Type: text/enriched; charset="iso-8859-1" First you need to compute a variable which identifies the episode for each client, say "EPISODE" (make sure this does what you wanted -- I'm not a whiz with the do if/lag stuff): Courier New   sort cases by clientid (a) date (a) ep_ct (a). compute episode = 1. do if clientid = lag(clientid) and ep_ct = lag(ep_ct). compute episode = lag(episode) + 1. else if clientid = lag(clientid) and (ep_ct - lag(ep_ct)) << 0. compute episode = episode + 1. else if clientid = lag(clientid) and (ep_ct - lag(ep_ct)) > 0. compute episode = lag(episode). else if clientid <<> lag(clientid). compute episode = 1. end if. list clientid date ep_ct episode.      List   CLIENTID DATE EP_CT EPISODE 161.00 01/01/01 1.00 1.00 161.00 02/01/01 2.00 1.00 161.00 03/01/01 3.00 1.00 161.00 04/25/01 1.00 2.00 161.00 05/25/01 2.00 2.00 161.00 06/25/01 3.00 2.00 175.00 01/01/02 1.00 1.00 175.00 02/01/02 1.00 2.00 175.00 03/01/02 1.00 3.00 175.00 04/01/02 1.00 4.00 Number of cases read: 10 Number of cases listed: 10 Then use the handy AGGREGATE command to summarize your data as follows: AGGREGATE /OUTFILE='C:\Data/myfilename.sav' /BREAK=clientid episode /tx_amts 'Total Treatment Cost per Episode' = SUM(tx_amount). This will create a new file, myfilename.sav, which includes variables: ClientId, episode, and tx_amts, which is the total amount for the episode for the client. Say you wanted a summary of how much the client spent, regardless of episode. In that case, change the BREAK to only include clientid. You can also compute other statistics using AGGREGATE, such as the minimum or maximum value or the mean. IE: AGGREGATE /OUTFILE='C:\Data/myfilename.sav' /BREAK=episode /avg_amte 'Mean Treatment Cost per Episode' = MEAN(tx_amount). would give the mean amount a client spent for each episode of care. Carol Courier New At 03:04 PM 10/9/02 -0700, Student wrote: >I am stuck on a syntax problem, and hoped you could help. Clients >(client ID) received TX (TX Amount) at varying times (some episodes had 1 >month, others more than 1 month). The EP_CT below delineates the episodes, >starting with the number 1 (i.e., episode 1 for client 161 consisted of >new# 1, 2, and 3; episode 2 had 4 months (1 to 4); and episode 3 had 3 >months). What I want is a case for each client-episode that totals the >Tx_amounts from each of the months in that episode. I have attempted >looping and Lag counting, but have been unsuccessful-- perhaps there is an >easier way? Any help would be appreciated. > > >TX_ID Mo_Yr ClientID EP_CT Tx_Amount >103 11/1/1999 161 1 11 >103 12/1/1999 161 2 31 >103 1/1/2000 161 3 3 >1220 2/1/2001 161 1 20 >1220 3/1/2001 161 2 31 >1220 4/1/2001 161 3 30 >1220 5/1/2001 161 4 6 >1220 9/1/2001 161 1 5 >1220 10/1/2001 161 2 1 >1220 11/1/2001 161 3 2 >289 1/1/2001 164 1 0 >289 2/1/2001 164 2 0 >289 6/1/2001 164 1 0 >289 10/1/2001 164 1 0 > >I want it to look something like this... >Client_ID Tx_Amnt Episode >161 45 1 >161 87 2 >161 8 3 >164 0 1 >etc.... > > ------------------------------------------------------------------------- Carol L. Albright, MS | E-Mail : calbright@visi.com Albright Consulting | Phone : 651/699-7218 St. Paul, MN 55105 USA | Research data services -------------------------------------------------------------------------

Back to: Top of message | Previous page | Main SPSSX-L page