Date: Thu, 14 Jun 2007 11:51:54 +1000
Reply-To: Frank Milthorpe <Frank.Milthorpe@planning.nsw.gov.au>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Frank Milthorpe <Frank.Milthorpe@planning.nsw.gov.au>
Subject: Re: R: Trying to obtain means with multiple weight variables in a
single step
In-Reply-To: <00a701c7adc8$27da4970$010aa8c0@acerd1fe3a0353>
Content-Type: text/plain; charset=ISO-8859-15
Luca and the rest of the list
This is a good start, however there is one aspect which I clearly didn't explain in sufficient detail in my original posting. The weights for each quarter vary. This is because the surveyed sample for the rolling 12 months will vary and the survey sample needs to be adjusted to match the population.
Hence instead of the data looking like:
1000 1 51 1 0 0 0 0 0 0 0
It is actually
1000 1 51 10 15 20 16 . . . .
In the above example there are four quarters with weights (that vary) between each quarter and four quarters which are not valid (shown as missing in the above). Each person can have a different weight which is based on location, age, gender and household type. Needless to say I need to use the weight already computed and stored on the file.
Currently I duplicate 4 records from each original record. I have done this using a LOOP and XSAVE, however it would be nice to know if it possible to undertake my analysis without having to do the data transformations.
Suggestions / comments would be very welcome.
Cheers
Frank
>>> "Luca Meyer" <lucameyer@tiscali.it> 14/06/2007 12:35 am >>>
Hello Frank,
I hope I understand your question. Here is a tested syntax to solve it:
/* first some sample data where the qX variables take values 1 if the
records refer to that quarter, otherwise is equal to 0 */
DATA LIST LIST/Person_no mode travel_time q1 q2 q3 q4 q5 q6 q7 q8.
BEGIN DATA
1000 1 51 1 0 0 0 0 0 0 0
1000 2 10 1 0 0 0 0 0 0 0
1000 3 74 1 0 0 0 0 0 0 0
1000 1 68 0 1 0 0 0 0 0 0
1000 2 5 0 1 0 0 0 0 0 0
1000 3 70 0 1 0 0 0 0 0 0
1000 1 58 0 0 1 0 0 0 0 0
1000 2 22 0 0 1 0 0 0 0 0
1000 3 68 0 0 1 0 0 0 0 0
1000 1 41 0 0 0 1 0 0 0 0
1000 2 0 0 0 0 1 0 0 0 0
1000 3 30 0 0 0 1 0 0 0 0
1001 1 35 1 0 0 0 0 0 0 0
1001 2 25 1 0 0 0 0 0 0 0
1001 3 71 1 0 0 0 0 0 0 0
1001 1 43 0 1 0 0 0 0 0 0
1001 2 18 0 1 0 0 0 0 0 0
1001 3 14 0 1 0 0 0 0 0 0
1001 1 29 0 0 1 0 0 0 0 0
1001 2 37 0 0 1 0 0 0 0 0
1001 3 78 0 0 1 0 0 0 0 0
1001 1 100 0 0 0 1 0 0 0 0
1001 2 12 0 0 0 1 0 0 0 0
1001 3 0 0 0 0 1 0 0 0 0
END DATA.
VAL LABEL MODE 1 'Car' 2 'Train' 3 'Bus'.
/* then let's create a variable indicating the quarter and drop the q1 to q8
*/
IF q1=1 quarter=1.
IF q2=1 quarter=2.
IF q3=1 quarter=3.
IF q4=1 quarter=4.
IF q5=1 quarter=5.
IF q6=1 quarter=6.
IF q7=1 quarter=7.
IF q8=1 quarter=8.
add files /file=* /drop=q1 to q8.
exe.
/* finally let's get the table you need */
means tables=travel_time by quarter /cells mean sum.
/* this one you might not need it but it will give you mean and total
travel_time by mode */
means tables=travel_time by mode /cells mean sum.
HTH,
Luca
Mr. Luca MEYER
Market research, data analysis & more
www.lucameyer.com - Tel: +39.339.495.00.21
-----Messaggio originale-----
Da: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] Per conto di Frank
Milthorpe
Inviato: mercoledì 13 giugno 2007 9.23
A: SPSSX-L@LISTSERV.UGA.EDU
Oggetto: Trying to obtain means with multiple weight variables in a single
step
Hi
I have data collected from a rolling survey. The data is collected each
quarter, however to obtain sufficient sample size data from the previous
4 quarters are combined. Lets ignore the starting quarters. So each data
record has:
Person_no mode travel_time q1 q2 q3 q4 q5 q6 q7 q8.
- 4 of the variables q1 to q8 will have valid (weight) data and the
other 4 quarter variables will have missing values.
This is a travel survey where mode is a category variable 1=Car 2=Train and
etc. Travel_time is continuous with values from 1 to say 100.
Person_no is just an ID so we can ignore this.
If I wish to obtain a "weighted" count of the people in each quarter I can
use the following command.
MEANS q1 q2 q3 q4 q5 q6 q7 q8 BY one / CELLS = SUM.
- where is a dummy variable which always takes the value 1.
If want the total trips by each mode I can use.
MEANS q1 q2 q3 q4 q5 q6 q7 q8 BY mode / CELLS = SUM.
What I want to do is obtain a table with the mean value of travel_time for
each quarter. I am struggling to find a way to do this easily, given that I
essentially have weights on my q1 .. q8 variables. I know that I can
reformat the data by using a LOOP and write out 4 records from each original
record and then process the data as per normal. I was wondering if anyone
had a suggestion that avoided this approach which I have overlooked.
Suggestions would be very welcome.
Cheers
Frank Milthorpe
News:
The majority of staff from the Transport and Population Data Centre have
moved to the Ministry of Transport. Contact details will be progressively
changed over the next few months.
Frank Milthorpe
Senior Manager, Transport Model Development Transport Data Centre NSW
Ministry of Transport
Direct: (02) 9206 8609 TDC Phone: (02) 9206 8611
Fax: (02) 9206 8691
Street: Level 7, Tower 2 (TNT Tower East), 1 Lawson Square, Redfern
NSW 2016
Postal: GPO Box 1620, Sydney NSW 2001
Email: frank.milthorpe@planning.nsw.gov.au
Web: www.transport.nsw.gov.au/tdc
----------------------------------------------------------------------------
--------------------------------------------------------------------
This message is intended for the addressee named and may contain
confidential/privileged information. If you are not the intended recipient,
please delete it and notify the sender.
Views expressed in this message are those of the individual sender, and are
not necessarily the views of the Department.
You should scan any attached files for viruses.
----------------------------------------------------------------------------
--------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.472 / Virus Database: 269.8.15/847 - Release Date: 12/06/2007
21.42
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.472 / Virus Database: 269.8.15/847 - Release Date: 12/06/2007
21.42
------------------------------------------------------------------------------------------------------------------------------------------------
This message is intended for the addressee named and may contain confidential/privileged information. If you are not the intended recipient, please delete it and notify the sender.
Views expressed in this message are those of the individual sender, and are not necessarily the views of the Department.
You should scan any attached files for viruses.
------------------------------------------------------------------------------------------------------------------------------------------------