# PS2.3 -- on covariance and corr. coeff. - Section 2.5 open data2-2 genr x = colgpa genr y = hsgpa genr n = $nobs # mean of colgpa genr xbar = mean(x) # s.d. of colgpa genr sx = sd(x) # mean of hsgpa genr ybar = mean(y) # s.d. of hsgpa genr sy = sd(y) # cross product of deviation from mean genr sxy = (x-xbar)*(y-ybar) # compute covariance genr covxy = sum(sxy)/(n-1) # compute correlation coefficient genr corxy = covxy/(sx*sy) # reset sample range smpl 1 1 # print values print xbar sx ybar sy covxy corxy # reset sample range smpl 1 427 # same with the corr command corr x y # summary statistics summary x y