Hi Listers,
I have below data set and
want to select four preceding days for analysis:
DATA LIST LIST /Date (Date10) Day Var_1.
BEGIN DATA 30-Sep-11 6 16603 1-Oct-11 7 13498 2-Oct-11 1 13197 3-Oct-11 2 15545 4-Oct-11 3 15796 5-Oct-11 4 17359 6-Oct-11 5 17499 7-Oct-11 6 19186 8-Oct-11 7 16323 9-Oct-11 1 12709 10-Oct-11 2 12923 11-Oct-11 3 13819 12-Oct-11 4 14922 13-Oct-11 5 14935 14-Oct-11 6 18419 15-Oct-11 7 15556 16-Oct-11 1 11535 17-Oct-11 2 13631 18-Oct-11 3 14266 19-Oct-11 4 14767 20-Oct-11 5 15300 21-Oct-11 6 21836 22-Oct-11 7 16603 23-Oct-11 1 13455 24-Oct-11 2 11873 25-Oct-11 3 14117 26-Oct-11 4 16365 27-Oct-11 5 15519 28-Oct-11 6 16682 29-Oct-11 7 14580 30-Oct-11 1 13072 31-Oct-11 2 20366 1-Nov-11 3 15300 2-Nov-11 4 21836 3-Nov-11 5 16603 4-Nov-11 6 13455 5-Nov-11 7 11873 END DATA. LIST.
For example,
when I select Sunday 5 November 2011 and want to compare the value (11873) in Var_1
column
with the average of
the four preceding Sundays - 29
Oct 2011, 22 Oct 2011, 15 Oct 2011 and 8 Oct 2011
How do I do it?
Thank in advance.
Boreak
This email is intended solely for the named addressee. If you are not the addressee indicated please delete it immediately. |
Hi Boreak,
I believe the 2nd column in your data is day right? Would you like to try filtering out those sunday first? it does make your work easier. Assuming that your second columnd variable is day, and please use a fre command to check if you have successsfully selected all the sundays. select if (day=7). fre day. After which, when you had filtered out the sundays, you can concentrate with selecting the dates for analysis. There are a few ways to do it. What I might do it. compute case=$casenum. /*create a case column so that you can make use of case to select a range of dates (good for small data)*/. exe. select if (case ge 1 and case le 4). fre date. /*assuming that date is your first column to check if these are the sundays you would like to analyze*/. PS: please remove my comments in the codes before running them. Warmest regards Dorraj Oet Date: Tue, 17 Jan 2012 13:06:50 +1100 From: [hidden email] Subject: How to select four preceding days To: [hidden email] Hi Listers,
I have below data set and want to select four preceding days for analysis:
DATA LIST LIST /Date (Date10) Day Var_1.
BEGIN DATA 30-Sep-11 6 16603 1-Oct-11 7 13498 2-Oct-11 1 13197 3-Oct-11 2 15545 4-Oct-11 3 15796 5-Oct-11 4 17359 6-Oct-11 5 17499 7-Oct-11 6 19186 8-Oct-11 7 16323 9-Oct-11 1 12709 10-Oct-11 2 12923 11-Oct-11 3 13819 12-Oct-11 4 14922 13-Oct-11 5 14935 14-Oct-11 6 18419 15-Oct-11 7 15556 16-Oct-11 1 11535 17-Oct-11 2 13631 18-Oct-11 3 14266 19-Oct-11 4 14767 20-Oct-11 5 15300 21-Oct-11 6 21836 22-Oct-11 7 16603 23-Oct-11 1 13455 24-Oct-11 2 11873 25-Oct-11 3 14117 26-Oct-11 4 16365 27-Oct-11 5 1551! 9 28-Oct-11 6 16682 29-Oct-11 7 14580 30-Oct-11 1 13072 31-Oct-11 2 20366 1-Nov-11 3 15300 2-Nov-11 4 21836 3-Nov-11 5 16603 4-Nov-11 6 13455 5-Nov-11 7 11873 END DATA. LIST.
For example, when I select Sunday 5 November 2011 and want to compare the value (11873) in Var_1 column
with the average of the four preceding Sundays - 29 Oct 2011, 22 Oct 2011, 15 Oct 2011 and 8 Oct 2011
How do I do it?
Thank in advance.
Boreak This email is intended solely for the named addressee. If you are not the addressee indicated please delete it immediately. |
Administrator
|
In reply to this post by Boreak Silk
CREATE Pre4AVG=PMA(Var_1,4).
Alternatively. IF $CASENUM > 4 Pre4Avg2=SUM(LAG(Var_1,1),LAG(Var_1,2),LAG(Var_1,3),LAG(Var_1,4))/4.
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?" |
Administrator
|
OOPS!! I misread the question as preceding days rather than Sundays ;=(
This is probably more like it. I am assuming that you have *COMPLETE DATA* otherwise things get more complex and you are better off selecting on DAY=7 and then doing your data checks and probably the PMA. -- if $CASENUM > 28 AND DAY=7 DIFFPre4=var_1 -SUM(LAG(Var_1,7),LAG(Var_1,14),LAG(Var_1,21),LAG(Var_1,28))/4.
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?" |
In reply to this post by Boreak Silk
SORT CASES BY Day .
CASESTOVARS /ID=Day /GROUPBY=VARIABLE. COMPUTE AVERAGE=MEAN( Var_1.1 TO Var_1.5). EXECUTE. NOW YOU CAN COMPARE DAY 1,2,3,4,5,6,7 |
Administrator
|
Best to leave the data in current form and simply use SPLIT FILE followed by CREATE ;-)
Keeps things a bit tidier! SORT CASES BY Day . SPLIT FILE BY DAY. CREATE V1_PMA4=PMA(Var_1,4). --
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?" |
Hi All,
Thank you all for your helps and they all work differently. However let me reiterate my question. I have a time series (more than 5 years) data set and I want to be able to run a syntax that select four preceding days (same Mon or Tues, ...) when a date corresponding date is selected. The data that I have looks like this: Date Year Month MDate Day Data 01/10/2009 2009 10 1 5 312 02/10/2009 2009 10 2 6 234 ...... 05/11/2011 2011 11 5 7 122 06/11/2011 2011 11 6 1 325 Where Month = Jan, Feb, ...., Dec MDate = 1, 2, ...., 29/30/31 Day = 1 (Sun), 2 (Mon), .... 7(Sat) For example, when I select 5 Nov 2011 which is Sat, the syntax should select the four preceding Saturdays. One way to do it is to create a new variable, named New_Date, by recoding something like: If (Year=2011 and Month=11 and Mday=5) New_Date=1. New_Date =9 for the four preceding Saturdays but I'm not sure how to create a short syntax to do this. I don't want to look up in a calendar and write another four lines of IF/Recode commands because I might select any date and I want to automate it. By creating a new variable I can use it to compare the data on 5 Nov 2011 with the average of four preceding Sat. Another question is if the data is on an hourly basis with additional variable - HOUR where Hour = 0 (12am-1am), 1 (1am-2am), 2 (2am-3am), ..., 24(11pm-12am) Date Year Month MDate HOUR Day Data 01/10/2009 2009 10 1 0 5 12 01/10/2009 2009 10 1 1 5 24 ...... 05/11/2011 2011 11 5 0 7 12 05/11/2011 2011 11 5 1 7 32 How do I do it? Thank and any further assistance will be appreciated. Regards, Boreak -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso Sent: Thursday, 19 January 2012 2:00 AM To: [hidden email] Subject: Re: How to select four preceding days Best to leave the data in current form and simply use SPLIT FILE followed by CREATE ;-) Keeps things a bit tidier! SORT CASES BY Day . SPLIT FILE BY DAY. CREATE V1_PMA4=PMA(Var_1,4). -- DEBOER wrote > > SORT CASES BY Day . > CASESTOVARS > /ID=Day > /GROUPBY=VARIABLE. > > > COMPUTE AVERAGE=MEAN( Var_1.1 TO Var_1.5). > EXECUTE. > > NOW YOU CAN COMPARE DAY 1,2,3,4,5,6,7 > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-select-four-precedi ng-days-tp5150444p5155059.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 email is intended solely for the named addressee. If you are not the addressee indicated please delete it immediately. ===================== 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 |
Administrator
|
I believe you need to study the date related functions in the manual.
What part of the solutions posted are not sufficient to address your initial question? The SPLIT followed by CREATE with PMA is about as simple and elegant as you are going to reach! As part of your job you should consider reading/browsing the fine manual!---
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?" |
Free forum by Nabble | Edit this page |