How to calculate the average for many observations?

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

How to calculate the average for many observations?

Dimitris Nikolaou
Hi to everybody!

I have recently come up with a problem. This is a general example:



age      sex       educ0   educ1   educ2   educ3     lnwage
20      male         1        0           0          0            0
20      male         1        0           0          0          9.65
20      male         1        0           0          0          8.56
20      male         0        1           0          0          7.65
20      male         0        1           0          0            0
20      male         0        0           1          0          8.23
20      male         0        0           1          0          8.15
20      male         0        0           1          0          8.00
20      male         0        0           1          0            0
20      male         0        0           0          1          8.88
20      male         0        0           0          1            0
20      male         0        0           0          1          6.57
20   female         1        0           0          0            0
20   female         1        0           0          0          9.65
20   female         1        0           0          0          8.56
20   female         0        1           0          0          7.65
20   female         0        1           0          0            0
20   female         0        0           1          0          8.23
20   female         0        0           1          0          8.15
20   female         0        0           1          0          8.00
20   female         0        0           1          0            0
20   female         0        0           0          1          8.88
20   female         0        0           0          1            0
20   female         0        0           0          1          6.57


I would like to find a way so as the spss to calculate the average for
eevery team. By this I mean I want to calculate the following:

if (age=20 and sex=male and educ0=1) then calculate (9.65+8.56)/2. The
average only for those who have wages.
if (age=20 and sex=male and educ1=1) then calculate (7.65)/1.
....
....
....
if (age=20 and sex=female and educ3=1) then calculate (8.88+6.57)/2.

And I want to do this for every age from 17 to 65. I tried to calculate it
but with no success. My only alternative is to make the calculations
manually. But I have to do this for about 800.000 observation and for more
than once.So I was wondering if there is a faster way.

Thanks in advance!

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
Reply | Threaded
Open this post in threaded view
|

comparing means for small unequal samples

Zdaniuk, Bozena
Hello, I want to compare means for two small unequal samples (6 vs 25).
Is it ok to just run t-test and look at the Levine test for unequal
variances or should I run a different test?
Thanks in advance.
Bozena Zdaniuk
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate the average for many observations?

Marks, Jim
In reply to this post by Dimitris Nikolaou
Is "0" defined as a missing value for lnwage? If so, 0 values will be
excluded from calculations.

This syntax creates a new dataset with the mean values.

*** sample data for illustration.
DATA LIST FREE /age (f8.0) sex  (a8) educ0  educ1  educ2 educ3 (4f8.0)
lnwage (f8.2).
BEGIN DATA
20      male         1        0           0          0            0
20      male         1        0           0          0          9.65
20      male         1        0           0          0          8.56
20      male         0        1           0          0          7.65
20      male         0        1           0          0            0
20      male         0        0           1          0          8.23
20      male         0        0           1          0          8.15
20      male         0        0           1          0          8.00
20      male         0        0           1          0            0
20      male         0        0           0          1          8.88
20      male         0        0           0          1            0
20      male         0        0           0          1          6.57
20   female         1        0           0          0            0
20   female         1        0           0          0          9.65
20   female         1        0           0          0          8.56
20   female         0        1           0          0          7.65
20   female         0        1           0          0            0
20   female         0        0           1          0          8.23
20   female         0        0           1          0          8.15
20   female         0        0           1          0          8.00
20   female         0        0           1          0            0
20   female         0        0           0          1          8.88
20   female         0        0           0          1            0
20   female         0        0           0          1          6.57
END DATA.

** define missing value-- not included in aggregate calculations.
MISSING VALUE lnwage (0).

*** valid for v14 and higher.
DATASET NAME origdata.
DATASET DECLARE aggrdata.

** for older versions provide a filename within single apostrophes (e.g.
'c:\path\fname.sav' ) in place of aggrdata


AGGREGATE OUTFILE  = aggrdata /BREAK = age sex educ0 educ1 educ2 educ3
  /lnwage = MEAN(lnwage).

--jim

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Dimitris Nikolaou
Sent: Monday, October 02, 2006 1:21 PM
To: [hidden email]
Subject: How to calculate the average for many observations?

Hi to everybody!

I have recently come up with a problem. This is a general example:



age      sex       educ0   educ1   educ2   educ3     lnwage
20      male         1        0           0          0            0
20      male         1        0           0          0          9.65
20      male         1        0           0          0          8.56
20      male         0        1           0          0          7.65
20      male         0        1           0          0            0
20      male         0        0           1          0          8.23
20      male         0        0           1          0          8.15
20      male         0        0           1          0          8.00
20      male         0        0           1          0            0
20      male         0        0           0          1          8.88
20      male         0        0           0          1            0
20      male         0        0           0          1          6.57
20   female         1        0           0          0            0
20   female         1        0           0          0          9.65
20   female         1        0           0          0          8.56
20   female         0        1           0          0          7.65
20   female         0        1           0          0            0
20   female         0        0           1          0          8.23
20   female         0        0           1          0          8.15
20   female         0        0           1          0          8.00
20   female         0        0           1          0            0
20   female         0        0           0          1          8.88
20   female         0        0           0          1            0
20   female         0        0           0          1          6.57


I would like to find a way so as the spss to calculate the average for
eevery team. By this I mean I want to calculate the following:

if (age=20 and sex=male and educ0=1) then calculate (9.65+8.56)/2. The
average only for those who have wages.
if (age=20 and sex=male and educ1=1) then calculate (7.65)/1.
....
....
....
if (age=20 and sex=female and educ3=1) then calculate (8.88+6.57)/2.

And I want to do this for every age from 17 to 65. I tried to calculate
it but with no success. My only alternative is to make the calculations
manually. But I have to do this for about 800.000 observation and for
more than once.So I was wondering if there is a faster way.

Thanks in advance!

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate the average for many observations?

Mahbub Khandoker
In reply to this post by Dimitris Nikolaou
Custom table can provide the averages.

A new database is created,

DATA LIST free/ age(n2) sex(a6) edu0 (n1) edu1(n1) edu2 (n2) edu3 (n2) inwage (f10.2).
Begin data
20 male 1 0 0 0 0
20 male 1 0 0 0 9.65
20 male 1 0 0 0 8.56
20 male 0 1 0 0 7.65
20 male 0 1 0 0 0
20 male 0 0 1 0 8.23
20 female 1 0 0 0 9.65
20 female 1 1 0 0 7.65
21 male 1 0 0 0 0
21 male 1 0 0 0 9.65
21 male 1 0 0 0 8.56
21 male 0 1 0 0 7.65
22 male 0 1 0 0 0
22 male 0 0 1 0 8.23
22 female 1 0 0 0 9.65
22 female 1 1 0 0 7.65
End data.
Execute.

* Custom Tables.
CTABLES
  /VLABELS VARIABLES=inwage age sex edu0 edu1 edu2 edu3
    DISPLAY=DEFAULT
  /TABLE age [C] > sex > edu0 [C] > edu1 [C] > edu2 [C] > edu3 [C] BY inwage
  [MEAN]
  /CATEGORIES VARIABLES=age sex edu0 edu1 edu2 edu3 ORDER=A KEY=VALUE
  EMPTY=EXCLUDE.


* ANOTHER way getting the averagesCustom Tables.
CTABLES
  /VLABELS VARIABLES=sex inwage age edu0 edu1 edu2 edu3
    DISPLAY=DEFAULT
  /TABLE age [C] > edu0 [C] > edu1 [C] > edu2 [C] > edu3 [C] BY sex > inwage
  [MEAN]
  /CATEGORIES VARIABLES=sex age edu0 edu1 edu2 edu3 ORDER=A KEY=VALUE
  EMPTY=EXCLUDE.

Thanks,
Mahbub




 -----Original Message-----
From:   SPSSX(r) Discussion [mailto:[hidden email]]  On Behalf Of Dimitris Nikolaou
Sent:   2-Oct-06 2:21 PM
To:     [hidden email]
Subject:             How to calculate the average for many observations?

Hi to everybody!

I have recently come up with a problem. This is a general example:



age      sex       educ0   educ1   educ2   educ3     lnwage
20      male         1        0           0          0            0
20      male         1        0           0          0          9.65
20      male         1        0           0          0          8.56
20      male         0        1           0          0          7.65
20      male         0        1           0          0            0
20      male         0        0           1          0          8.23
20      male         0        0           1          0          8.15
20      male         0        0           1          0          8.00
20      male         0        0           1          0            0
20      male         0        0           0          1          8.88
20      male         0        0           0          1            0
20      male         0        0           0          1          6.57
20   female         1        0           0          0            0
20   female         1        0           0          0          9.65
20   female         1        0           0          0          8.56
20   female         0        1           0          0          7.65
20   female         0        1           0          0            0
20   female         0        0           1          0          8.23
20   female         0        0           1          0          8.15
20   female         0        0           1          0          8.00
20   female         0        0           1          0            0
20   female         0        0           0          1          8.88
20   female         0        0           0          1            0
20   female         0        0           0          1          6.57


I would like to find a way so as the spss to calculate the average for
eevery team. By this I mean I want to calculate the following:

if (age=20 and sex=male and educ0=1) then calculate (9.65+8.56)/2. The
average only for those who have wages.
if (age=20 and sex=male and educ1=1) then calculate (7.65)/1.
....
....
....
if (age=20 and sex=female and educ3=1) then calculate (8.88+6.57)/2.

And I want to do this for every age from 17 to 65. I tried to calculate it
but with no success. My only alternative is to make the calculations
manually. But I have to do this for about 800.000 observation and for more
than once.So I was wondering if there is a faster way.

Thanks in advance!

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate the average for many observations?

Naila Baig-Ansari-2
In reply to this post by Dimitris Nikolaou
 Hi Dimitris,

Try this syntax.  It basically selects only those variables that have a wage
and then splits the file into the groups you wanted.  In the final step, it
calculates the MEAN:

USE ALL.
COMPUTE filter_$=(lnwage > 0).
VARIABLE LABEL filter_$ 'lnwage > 0 (FILTER)'.
VALUE LABELS filter_$  0 'Not Selected' 1 'Selected'.
FORMAT filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE .

SORT CASES BY age sex educ0 educ1 educ2 educ3 .
SPLIT FILE
  LAYERED BY age sex educ0 educ1 educ2 educ3 .

FREQUENCIES
  VARIABLES=lnwage
  /STATISTICS=MEAN
  /ORDER=  ANALYSIS .

Best
Naila
-------------------------------------------------------------------------
"Our lives begin to end the day we become silent about things that matter"
Dr. Martin Luther King, Jr


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Dimitris Nikolaou
Sent: Monday, October 02, 2006 11:21 PM
To: [hidden email]
Subject: How to calculate the average for many observations?

Hi to everybody!

I have recently come up with a problem. This is a general example:



age      sex       educ0   educ1   educ2   educ3     lnwage
20      male         1        0           0          0            0
20      male         1        0           0          0          9.65
20      male         1        0           0          0          8.56
20      male         0        1           0          0          7.65
20      male         0        1           0          0            0
20      male         0        0           1          0          8.23
20      male         0        0           1          0          8.15
20      male         0        0           1          0          8.00
20      male         0        0           1          0            0
20      male         0        0           0          1          8.88
20      male         0        0           0          1            0
20      male         0        0           0          1          6.57
20   female         1        0           0          0            0
20   female         1        0           0          0          9.65
20   female         1        0           0          0          8.56
20   female         0        1           0          0          7.65
20   female         0        1           0          0            0
20   female         0        0           1          0          8.23
20   female         0        0           1          0          8.15
20   female         0        0           1          0          8.00
20   female         0        0           1          0            0
20   female         0        0           0          1          8.88
20   female         0        0           0          1            0
20   female         0        0           0          1          6.57


I would like to find a way so as the spss to calculate the average for
eevery team. By this I mean I want to calculate the following:

if (age=20 and sex=male and educ0=1) then calculate (9.65+8.56)/2. The
average only for those who have wages.
if (age=20 and sex=male and educ1=1) then calculate (7.65)/1.
....
....
....
if (age=20 and sex=female and educ3=1) then calculate (8.88+6.57)/2.

And I want to do this for every age from 17 to 65. I tried to calculate it
but with no success. My only alternative is to make the calculations
manually. But I have to do this for about 800.000 observation and for more
than once.So I was wondering if there is a faster way.

Thanks in advance!

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/