LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2007)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 14 Nov 2007 13:42:24 -0500
Reply-To:     Richard Ristow <wrristow@mindspring.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
Comments:     To: Mark Palmberg <mark-palmberg@uiowa.edu>,
              ViAnn Beadle <vab88011@gmail.com>
From:         Richard Ristow <wrristow@mindspring.com>
Subject:      Re: CASESTOVARS with a VARS limit
In-Reply-To:  <001701c826e1$bbad1a00$33074e00$@com>
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 12:13 PM 11/14/2007, ViAnn Beadle wrote:

>I don't think you'll run into variable limitations but you might >suffer from brain freeze ;-)

I won't post the FAQ about case and variable limits; but, no, you won't hit variable limitations. But your records, and your code, will get more complex.

>Make sure your resulting date variables are in time order and >variable order. Then you can use a loop across vectors to datediff >your date variables. Something like the following which is >completely untested calculates the interval between gifts (not the >interval between the first and this gift): > >vector datevar= date1 to date4/datediffvar(3). >loop #i=2 to 4. >. compute datediffvar(#i)= > datediff(datevar(#i),datevar(#i-1),"days"). >end loop.

Exactly. But as an illustration of styles, this is the equivalent, with the data in 'long' form. It's actually more lines (because of '#NewGuy', plus commenting and decoration); but, I think, simpler underlying logic. And it has no dependency on the actual or maximum number of gifts per ID. Not tested:

* Flag the first record for an ID. . * (This can be done more simply by . * ADD VARIABLES/FILE=*/BY ID/FIRST=NewGuy. . * but that makes 'NewGuy' a regular variable, not a . * scratch variable, so you have to decide whether . * keep it or drop it from your final data. Of course,. * if the next step is AGGREGATE, odds-and-ends . * variables like that will disappear anyway.) .

NUMERIC #NewGuy (F2) /* Flag first record for an ID */.

DO IF MISSING(LAG(ID)) OR LAG(ID) NE ID. COMPUTE #NewGuy = 1. ELSE. COMPUTE #NewGuy = 0. END IF.

* Difference in days between successive gifts . * (Requires data be sorted by ID and gift date.) .

NUMERIC BtwnGift (F4). VAR LABEL BtwnGift 'Time, days, since previous gift'.

IF NOT #NewGuy BtwnGift = datediff(GFTDAT,LAG(GFTDAT),"days"). ............. Going forward, at 11:43 AM 11/14/2007, Mark Palmberg wrote:

>>There are additional variables in my underlying data source that I >>may want to incorporate at some point (GFTYP [type], GFTARA [area], >>etc.), so my total number of variables will scale up pretty quickly.

Again, there are tastes and style. For me, the more variables there are per gift (or other instance, such as office visit), the more I'd try not to go to 'wide' organization.

Ah, well. Go in peace, upon the path.

-Happy analysis, Richard

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (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 LISTSERV@LISTSERV.UGA.EDU (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


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