Aggregating Dates With GPL

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

Aggregating Dates With GPL

Robert Walker
Dear All,

A GPL question... I have thousands of respondents from a continuous tracking study who provide monthly household grocery spending.

I would like to produce a line or bar graph that simply shows average spending per month (i.e., show one summary mean value per month), but GPL treats each case as an observation. This code produces a line graph with months along the x-axis, yet a line that reflects each and every date. So, what am I missing?

GGRAPH /GRAPHDATASET NAME="FD" VARIABLES=MEAN(Spend) Period /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s = userSource(id("FD"))
DATA: Period = col(source(s), name("Period"), unit.time())
DATA: Spend = col(source(s), name("MEAN_Spend"))
GUIDE: axis(dim(1), label("Period"))
GUIDE: axis(dim(2), label("HH Spending"))
SCALE: time(dim(1), dataMaximum())
ELEMENT: line(position(summary.mean(Period*Spend)))
END GPL.

Thanks in advance,

Bob Wakler
Surveys & Forecasts, LLC

=====================
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: Aggregating Dates With GPL

Jignesh Sutar
Hi Bob, The below demonstrates, I believe, what you are trying to achieve:

data list list / id (n) date (1adate).
begin data.
1 1/1/2014
2 1/2/2014
3 1/3/2014
4 1/4/2014
5 1/5/2014
6 1/6/2014
7 1/7/2014
8 1/8/2014
9 1/9/2014
10 1/10/2014
11 1/11/2014
12 1/12/2014
13 1/1/2014
14 1/2/2014
15 1/3/2014
16 1/4/2014
17 1/5/2014
18 1/6/2014
19 1/7/2014
20 1/8/2014
21 1/9/2014
22 1/10/2014
23 1/11/2014
24 1/12/2014
end data.
set seed = 10.
compute Spend=rv.uniform(0,1)*100.
ctables /table date[c] by Spend[s] [mean f8.2 validn f8.0 minimum f8.1 maximum f8.1].

* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=date MEAN(Spend)[name="MEAN_Spend"] MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: date=col(source(s), name("date"))
  DATA: MEAN_Spend=col(source(s), name("MEAN_Spend"))
  GUIDE: axis(dim(1), label("date"))
  GUIDE: axis(dim(2), label("Mean Spend"))
  ELEMENT: line(position(date*MEAN_Spend), label(MEAN_Spend))
END GPL.

Reply | Threaded
Open this post in threaded view
|

Re: Aggregating Dates With GPL

Robert Walker
Hi Jignesh,

Thanks so much for your time in trying to help me solve this. I think that I am forgetting that GGRAPH and GPL make no assumptions about the level of aggregation of the data being graphed. That, I am assuming, must happen well before the GPL code, as there is no built-in aggregation function that I could find that would help with dates. Specifically, if I have multiple daily entries from survey research, GPL plots every data point. Ugh.

So this is basically what I am trying to do; I want to change the color of the mean values and remove the boxes around them, but this produces a monthly mean graph:

data list list / date (ADATE10) spend (DOLLAR8).
begin data.
9/21/14 $100
9/24/14 $100
9/26/14 $100
9/28/14 $100
10/6/14 $100
9/19/14 $180
10/2/14 $165
10/11/14 $145
10/31/14 $1150
1/24/15 $125
9/11/14 $290
9/26/14 $265
9/28/14 $233
10/6/14 $215
10/20/14 $550
10/28/14 $350
12/31/14 $760
1/19/15 $1200
10/15/14 $100
10/22/14 $100
10/27/14 $100
11/12/14 $100
11/19/14 $100
11/24/14 $100
12/9/14 $100
12/10/14 $100
12/15/14 $100
1/15/15 $100
1/20/15 $100
1/20/15 $100
1/26/15 $100
2/2/15 $100
2/6/15 $540
2/14/15 $220
1/22/15 $109
1/20/15 $110
9/28/14 $120
11/2/14 $120
1/8/15 $120
1/29/15 $120
11/6/14 $123
10/4/14 $125
10/16/14 $125
12/17/14 $125
12/18/14 $125
1/11/15 $125
1/13/15 $125
1/21/15 $125
1/26/15 $125
10/10/14 $130
10/22/14 $130
12/21/14 $130
1/24/15 $130
9/7/14 $140
12/9/14 $140
12/10/14 $140
9/3/14 $150
9/3/14 $150
9/4/14 $150
9/4/14 $150
9/5/14 $150
9/5/14 $150
9/7/14 $150
9/12/14 $150
9/12/14 $150
9/17/14 $150
9/21/14 $150
9/24/14 $150
10/5/14 $150
10/9/14 $150
10/11/14 $150
10/13/14 $150
10/16/14 $150
10/25/14 $150
11/12/14 $150
11/12/14 $150
11/13/14 $150
11/14/14 $150
11/14/14 $150
11/20/14 $150
11/20/14 $150
11/24/14 $150
11/29/14 $150
11/29/14 $150
12/2/14 $150
12/17/14 $150
12/18/14 $150
12/24/14 $150
12/25/14 $150
12/29/14 $150
1/3/15 $150
1/4/15 $150
1/4/15 $150
1/6/15 $150
1/7/15 $150
1/7/15 $150
1/7/15 $150
1/10/15 $150
1/12/15 $150
1/12/15 $150
1/18/15 $150
1/20/15 $150
1/22/15 $150
1/22/15 $150
1/23/15 $150
1/27/15 $150
1/28/15 $150
1/28/15 $160
9/21/14 $170
11/4/14 $175
9/2/14 $180
10/24/14 $180
end data.

FORMATS date (MOYR6).
ALTER TYPE date (A6).
AGGREGATE OUTFILE=* /BREAK=date /spend=MEAN(spend).
ALTER TYPE date (MOYR6).
FORMATS spend (DOLLAR8.0).

GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=date spend MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: date=col(source(s), name("date"))
  DATA: spend=col(source(s), name("spend"))
  GUIDE: axis(dim(1), label("Month") )
  GUIDE: axis(dim(2), label("Average Spend"))
  ELEMENT: line(position(date*spend), label(spend), color(color.blue))
END GPL.

Thak you Jignesh!

Bob Walker
Surveys & Forecasts, LLC

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jignesh Sutar
Sent: Sunday, February 22, 2015 4:31 AM
To: [hidden email]
Subject: Re: Aggregating Dates With GPL

Hi Bob, The below demonstrates, I believe, what you are trying to achieve:

data list list / id (n) date (1adate).
begin data.
1 1/1/2014
2 1/2/2014
3 1/3/2014
4 1/4/2014
5 1/5/2014
6 1/6/2014
7 1/7/2014
8 1/8/2014
9 1/9/2014
10 1/10/2014
11 1/11/2014
12 1/12/2014
13 1/1/2014
14 1/2/2014
15 1/3/2014
16 1/4/2014
17 1/5/2014
18 1/6/2014
19 1/7/2014
20 1/8/2014
21 1/9/2014
22 1/10/2014
23 1/11/2014
24 1/12/2014
end data.
set seed = 10.
compute Spend=rv.uniform(0,1)*100.
ctables /table date[c] by Spend[s] [mean f8.2 validn f8.0 minimum f8.1 maximum f8.1].

* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=date MEAN(Spend)[name="MEAN_Spend"] MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: date=col(source(s), name("date"))
  DATA: MEAN_Spend=col(source(s), name("MEAN_Spend"))
  GUIDE: axis(dim(1), label("date"))
  GUIDE: axis(dim(2), label("Mean Spend"))
  ELEMENT: line(position(date*MEAN_Spend), label(MEAN_Spend)) END GPL.

<http://spssx-discussion.1045642.n5.nabble.com/file/n5728772/Capture.png>



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Aggregating-Dates-With-GPL-tp5728768p5728772.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

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