|
Is it possible to make lag function more complex? For instance if the second
observation if i am looking for is the first observation +1. I've tried the following syntax and it doesn't seem to work IF start_date=LAG(start_date+1)) STCNT=LAG(STCNT) +1. ===================== 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 |
|
Yes. This is from the SPSS help.
LAG(arg,n) The value of the variable n cases before. The first argument is a variable. The second argument, if specified, is a constant and must be a positive integer; the default is 1. For example, PREV4=LAG(GNP,4) returns the value of GNP for the fourth case before the current one. The first four cases have system-missing values for PREV4. So to go back to the 2nd lag you would do lag(arg,2). Melissa -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Alina Sheyman Sent: Wednesday, October 08, 2008 11:12 AM To: [hidden email] Subject: [SPSSX-L] lag function Is it possible to make lag function more complex? For instance if the second observation if i am looking for is the first observation +1. I've tried the following syntax and it doesn't seem to work IF start_date=LAG(start_date+1)) STCNT=LAG(STCNT) +1. ===================== 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 PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. ===================== 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 |
|
The problem is that I don't want the value of the second case preceding my
observation, but rather the value of the first case preceding the observation - 1 IF start_date=LAG(start_date-1)) STCNT=LAG(STCNT) +1. ie. st_date stcnt 12-1 1 10-2 2 7-3 3 so in this example if the next start date is 7-2, a new stcnt value of 4 should be returned, if not then not the new observation should be (10-1) On Wed, Oct 8, 2008 at 12:15 PM, Melissa Ives <[hidden email]> wrote: > Yes. This is from the SPSS help. > LAG(arg,n) The value of the variable n cases before. The first argument is > a variable. The second argument, if specified, is a constant and must be a > positive integer; the default is 1. For example, PREV4=LAG(GNP,4) returns > the value of GNP for the fourth case before the current one. The first four > cases have system-missing values for PREV4. > > So to go back to the 2nd lag you would do lag(arg,2). > > Melissa > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of > Alina Sheyman > Sent: Wednesday, October 08, 2008 11:12 AM > To: [hidden email] > Subject: [SPSSX-L] lag function > > Is it possible to make lag function more complex? For instance if the > second observation if i am looking for is the first observation +1. I've > tried the following syntax and it doesn't seem to work > > IF start_date=LAG(start_date+1)) STCNT=LAG(STCNT) +1. > > ===================== > 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 > > PRIVILEGED AND CONFIDENTIAL INFORMATION > This transmittal and any attachments may contain PRIVILEGED AND > CONFIDENTIAL information and is intended only for the use of the > addressee. If you are not the designated recipient, or an employee > or agent authorized to deliver such transmittals to the designated > recipient, you are hereby notified that any dissemination, > copying or publication of this transmittal is strictly prohibited. If > you have received this transmittal in error, please notify us > immediately by replying to the sender and delete this copy from your > system. You may also call us at (309) 827-6026 for assistance. > ===================== 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 |
|
Perhaps I misunderstand the question, but what about something like this:
IF (start_date=LAG(start_date)+1) STCNT=LAG(STCNT) +1. (Of couse if "date" is really a date, you should use date arithmetic - functions like datediff.) Jan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Alina Sheyman Sent: Wednesday, October 08, 2008 6:25 PM To: [hidden email] Subject: Re: lag function The problem is that I don't want the value of the second case preceding my observation, but rather the value of the first case preceding the observation - 1 IF start_date=LAG(start_date-1)) STCNT=LAG(STCNT) +1. ie. st_date stcnt 12-1 1 10-2 2 7-3 3 so in this example if the next start date is 7-2, a new stcnt value of 4 should be returned, if not then not the new observation should be (10-1) On Wed, Oct 8, 2008 at 12:15 PM, Melissa Ives <[hidden email]> wrote: > Yes. This is from the SPSS help. > LAG(arg,n) The value of the variable n cases before. The first > argument is a variable. The second argument, if specified, is a > constant and must be a positive integer; the default is 1. For > example, PREV4=LAG(GNP,4) returns the value of GNP for the fourth case > before the current one. The first four cases have system-missing values for PREV4. > > So to go back to the 2nd lag you would do lag(arg,2). > > Melissa > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf > Of Alina Sheyman > Sent: Wednesday, October 08, 2008 11:12 AM > To: [hidden email] > Subject: [SPSSX-L] lag function > > Is it possible to make lag function more complex? For instance if the > second observation if i am looking for is the first observation +1. > I've tried the following syntax and it doesn't seem to work > > IF start_date=LAG(start_date+1)) STCNT=LAG(STCNT) +1. > > ===================== > 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 > > PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any > attachments may contain PRIVILEGED AND CONFIDENTIAL information and is > intended only for the use of the addressee. If you are not the > designated recipient, or an employee or agent authorized to deliver > such transmittals to the designated recipient, you are hereby notified > that any dissemination, copying or publication of this transmittal is > strictly prohibited. If you have received this transmittal in error, > please notify us immediately by replying to the sender and delete this > copy from your system. You may also call us at (309) 827-6026 for > assistance. > ===================== 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 _____________ Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem. Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její přílohy? Myslete na přírodu. This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission. Are you sure that you really need a print version of this message and/or its attachments? Think about nature. -.- -- ===================== 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 |
|
In reply to this post by Alina Sheyman-3
At 12:12 PM 10/8/2008, Alina Sheyman wrote:
>Is it possible to make lag function more complex? For instance if >the second observation if i am looking for is the first observation >+1. I've tried the following syntax and it doesn't seem to work > >IF start_date=LAG(start_date+1)) STCNT=LAG(STCNT) +1. To start with, you have a missing left parenthesis; I suppose you mean IF (start_date=LAG(start_date+1)) STCNT=LAG(STCNT) +1. Melissa's answer may have given you what you need; but I'm not sure, since I can't tell what you are looking for. "STCNT=LAG(STCNT) +1" is a valid computation, either in a COMPUTE or an IF statement. Be careful, though, if you execute it conditionally, in an IF or a DO IF: In some logic, when it's not executed, STCNT is left system-missing, and all later values of STCNT are missing as well. "LAG(start_date+1)" is >not< a valid use of the LAG function; the argument (or first argument) to LAG must be a variable, not an expression. This is where I lose your meaning: what did you want, using LAG that way? -Good luck, Richard ===================== 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 |
|
this is the statement that I'm trying to use
IF (start_date=(LAG(range(datediff(start_date, ,"days"),1,3)) STCNT=LAG(STCNT) +1). ie. st_date stcnt 12-1 1 10-2 2 7-3 3 so in this example if the next start date is in the range of 1-3 days from 7-3, a new stcnt value of 4 should be returned, if not then not On Wed, Oct 8, 2008 at 12:41 PM, Richard Ristow <[hidden email]>wrote: > At 12:12 PM 10/8/2008, Alina Sheyman wrote: > > Is it possible to make lag function more complex? For instance if the >> second observation if i am looking for is the first observation +1. I've >> tried the following syntax and it doesn't seem to work >> >> IF start_date=LAG(start_date+1)) STCNT=LAG(STCNT) +1. >> > > To start with, you have a missing left parenthesis; I suppose you mean > > IF (start_date=LAG(start_date+1)) STCNT=LAG(STCNT) +1. > > > Melissa's answer may have given you what you need; but I'm not sure, since > I can't tell what you are looking for. > > "STCNT=LAG(STCNT) +1" is a valid computation, either in a COMPUTE or an IF > statement. Be careful, though, if you execute it conditionally, in an IF or > a DO IF: In some logic, when it's not executed, STCNT is left > system-missing, and all later values of STCNT are missing as well. > > "LAG(start_date+1)" is >not< a valid use of the LAG function; the argument > (or first argument) to LAG must be a variable, not an expression. This is > where I lose your meaning: what did you want, using LAG that way? > > -Good luck, > Richard > > ===================== 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 |
|
At 12:49 PM 10/8/2008, Alina Sheyman wrote:
>this is the statement that I'm trying to use > >IF (start_date=(LAG(range(datediff(start_date, ,"days"),1,3)) > STCNT=LAG(STCNT) +1). You're confused several ways, here. First, as you've found, you can only lag a variable, not a computed quantity like "range(datediff(start_date, ,"days"),1,3)" Second, that isn't a valid computed quantity, anyway. "datediff" takes three arguments, and in your expression, you don't have the second one. You probably mean something like, IF RANGE(DATEDIFF(start_date,LAG(start_date),0,3) STCNT=LAG(STCNT) +1). But that won't work for you either, since in the data below, >ie. st_date stcnt > 12-1 1 > 10-2 2 > 7-3 3 'st_date' is not an SPSS date value, and DATEDIFF only works with SPSS date values. ===================== 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 |
| Free forum by Nabble | Edit this page |
