Chapter 2 - STATISTICS FOR BUSINESS & ECONOMICS by Paul Newbold
```*****************************************************************************
* CHAPTER 2 - STATISTICS FOR BUSINESS & ECONOMICS, 4th Ed., by Paul Newbold *
*****************************************************************************
*
* Example 2.1, page 11
*
* The SAMPLE command specifies the beginning and ending observation.  The
* format of the command is:
*
*     SAMPLE beg end
*
* where: beg = the beginning observation
*        end = the ending observation
*
SAMPLE 1 8
*
* The READ command inputs the data and assigns variable names.  The format
* of the READ command is:
*
*
* where: vars    = is a list of variable names
*        options = is a list of desired options
*
* The LIST option is used on the READ command to list all the data that has
*
13.6
25.5
43.6
-19.8
-13.8
12.0
36.3
14.3
*
* The STAT command automatically prints the MEAN of the variable specified.
* The format of the STAT command is:
*
*      STAT vars / options
*
* where: vars    = a list of variable names
*        options = a list of desired options
*
* The SUMS= option is used to store the sum of the variable EPS in a constant
* called MEAN.  This value will be used later in the chapter.
*
STAT EPS / SUMS=MEAN
*
*----------------------------------------------------------------------------
* Example 2.2, page 11
*
SAMPLE 1 7
4.0
14.3
19.0
-14.7
-26.5
37.2
23.8
STAT STOCKS
*
*----------------------------------------------------------------------------
* Example 2.3, page 14
*
SAMPLE 1 50
1  1
3  1
1  1
2  1
0  1
0  1
2  1
0  1
0  1
1  1
0  1
2  1
2  1
2  1
2  1
1  1
1  1
0  1
3  1
2  1
3  1
1  1
2  1
1  1
3  1
0  1
2  1
2  1
2  1
1  1
1  1
2  1
1  1
0  1
3  1
0  1
2  1
1  1
2  1
1  1
1  1
0  1
2  1
2  1
0  1
3  1
1  1
2  1
0  1
1  1
*
* The PFREQ option on the STAT command prints the table of frequencies of
* occurrence for each observed value in the data.  The median, mode and
* quartiles are also printed.
*
*
*----------------------------------------------------------------------------
* Example 2.4, page 18
*
SAMPLE 1 7
6.5
4.4
3.8
6.9
8.0
5.8
5.1
GEN1 N=7
*
* The Mean Percentage of the Common Stocks from Example 2.2.
*
GENR STOCKS2=STOCKS**2
*
* The STAT command with the MEAN= option saves the mean of the variable
* STOCKS in the constant MEANST.
*
STAT STOCKS / MEAN=MEANST
*
* The STAT command with the SUMS= options stores the sum of the variable
* STOCKS2 in the constant SSR.
*
STAT STOCKS2 / SUMS=SSR
GEN1 VARST=(SSR/N)-(MEANST**2)
GEN1 SDST=SQRT(VARST)
*
* The PRINT command lists variables specified.  The format of the command
* is:
*
*      PRINT vars / options
*
* where: vars    = a list of variables
*        options = a list of desired options
*
* The Mean of Common Stocks is MEANST, the Sum of Squared Returns on
* Commons Stocks is SSR, the Variance of Common Stocks is VARST, and the
* Standard Deviation of Common Stocks is SDST.
*
PRINT MEANST SSR VARST SDST
*
* The Sum of Squared Returns on Annual Percentage Returns on U.S. Treasury
* Bills is SSRTB, the Mean of Treasury Bills is MEANTB, the Variance of
* Treasury Bills is VARTB and the Standard Deviation of Treasury Bills is
* SDTB.
*
GENR TBILLS2=TBILLS**2
STAT TBILLS2 / SUMS=SSRTB
STAT TBILLS / SUMS=SUMTB
GEN1 MEANTB=SUMTB/N
GEN1 VARTB=(SSRTB/N)-(MEANTB**2)
GEN1 SDTB=SQRT(VARTB)
PRINT MEANTB SSRTB VARTB SDTB
*
*----------------------------------------------------------------------------
* Example 2.5, page 22
*
* Recall from Example 2.1, the Mean of the Earnings for the Eight Corporations
* was stored in the constant called MEAN.
*
SAMPLE 1 8
GEN1 N=8
GENR EPS2=EPS**2
STAT EPS2 / SUMS=SUMEPS
GEN1 VAR=(SUMEPS-N*(MEAN**2))/(N-1)
GEN1 SD=SQRT(VAR)
PRINT N MEAN SUMEPS VAR SD
*
*----------------------------------------------------------------------------
* Example 2.6, page 23
*
SAMPLE 1 7
34500
30700
32900
36000
34100
33800
32500
STAT SHOPSAL / SUMS=SUMSP
GEN1 N=7
GEN1 MEANS=SUMSP/N
GENR XMEAN=SHOPSAL-MEANS
GENR ABSA=ABS(XMEAN)
*
* Replicate the calculations for Mean Absolute Deviations Table on page 23.
*
PRINT SHOPSAL XMEAN ABSA
STAT XMEAN / SUMS=SXMEAN
STAT ABSA / SUMS=SABSA
PRINT SXMEAN SABSA
*
*-----------------------------------------------------------------------------
* Example 2.7, page 24
*
* The MINIM= and MAXIM= options on the STAT command saves the minimum value
* and maximum value of the variable SHOPSAL into a vector called MIN and MAX.
* The GEN1 command is then used to calculate the range between the largest
* and smallest value of the shop-floor supervisory staff's salary.
*
STAT SHOPSAL / MINIM=MIN MAXIM=MAX
GEN1 RANGE=MAX-MIN
PRINT RANGE
*
*-----------------------------------------------------------------------------
* Example 2.8, page 26
*
* The PFREQ option on the STAT command automatically sorts the data in
* ascending order before the median, mode and quartiles of the variable
* specified.
*
SAMPLE 1 8
STAT EPS / PFREQ
*
DELETE / ALL
*-----------------------------------------------------------------------------
* Example 2.9, page 34
*
SAMPLE 1 18
0.00   84
0.05  113
0.10  112
0.15   85
0.20   77
0.25   58
0.30   75
0.40   48
0.50   40
0.05   84
0.10  113
0.15  112
0.20   85
0.25   77
0.30   58
0.40   75
0.50   48
1.00   40
*
* The sample range is changed from 1 18 to 1 9 since only the first 9
* observations are used in the calculations.  Observations in Row 10 to 18
* are identical to those in Rows 1 to 9.
*
SAMPLE 1 9
*
* The GEN1 command with the SUM(x,n) option is used to sum the first 9
* observations of the variable FREQ.
*
GEN1 SUM=SUM(FREQ,9)
PRINT SUM
*
* Calculate the Relative (RFEQ) and Cumulative Relative (CFREQ) Frequencies.
*
GENR RFREQ=FREQ/SUM
GENR CFREQ=SUM(FREQ/SUM)
*
* Print the Frequencies (FREQ), Relative Frequencies (RFREQ), and Cumulative
* Relative Frequencies (CFREQ).
*
PRINT FREQ RFREQ CFREQ
*
* The sample range is changed from 1 9 to 1 18 since all 18 observations are
* required to replicate Figure 2.10 on page 36.  The last 3 observations of
* data in the Table on page 34 does not match those in Figure 2.10.  Below
* is a plot of what the Figure 2.10 should look like based on the data found
* in the Table on page 34.
*
SAMPLE 1 18
PLOT FREQ RANGE / NOPRETTY YMIN=0 YMAX=120 XMIN=0 XMAX=1.0
*
*-----------------------------------------------------------------------------
* Example 2.10, page 41
*
SAMPLE 1 5
0   2  2  1
2   4  3  3
4   6  6  5
6   8  5  7
8  10  4  9
*
STAT BATCHES / SUMS=N
GENR FM=BATCHES*M
GENR FM2=BATCHES*(M**2)
STAT FM / SUMS=SUMFM
STAT FM2 / SUMS=SUMFM2
PRINT N SUMFM SUMFM2
GEN1 MEAN=SUMFM/N
GEN1 VAR=(SUMFM2-(N*(MEAN**2)))/(N-1)
GEN1 SD=SQRT(VAR)
*
* The Mean, Variance and Standard Deviation of the sample are:
*
PRINT MEAN VAR SD
*
*----------------------------------------------------------------------------
*
STOP
```