Estimation and Inference
The purpose of this
lesson is to introduce some of the LIMDEP procedures for estimation and
hypothesis testing. We also show how to test for normality.
Reset $
/* The next line
will read a data file. Click here to obtain the data for this
lesson. Cut and paste the data into a data file called OSTROM.DAT. Or, use one
of the other ways of getting data into LIMDEP such as a spreadsheet. Note that
the data in this lesson are US and USSR defense spending for the indicated
years. Change the path to find data. */
Read ; File =
w:/bdanwood/OSTROM.DAT ? Read for files on disk
; Nvar = 3 ? Number of variables
; Nobs = 22 ? Number of observations
; Names = YEAR,US,USSR $ ? Names the Variables
/* The next line sets the sample for observations 1 through 22 */
Sample; 1-22 $
/* Now let's print
the data. */
List ; YEAR,US,USSR
$
/* Now let's
compute some descriptive statistics using LIMDEP's canned procedures. Note that
the Output option gives particular output that you want, including a
correlation matrix. The Quantile and Plot option calls for quantiles and plots
which are used in testing for normality. An S shaped curve in the plots
suggests non-normality, but this test may not be very reliable with small
samples. The All option calls for skew and kurtosis statistics which is another
way of checking for non-normality. Skew and kurtosis should both be near zero
for a normal distribution. */
Dstats ;
Rhs=YEAR,US,USSR ; Output=3 ; Quantiles; Plot ; All $
/* You can also
conduct a more formal test for normality, the Bowman and Shenton normality
test. This test is compared with a Chi-Squared distribution with two degrees of
freedom. Let's compute the test statistic for the variable US above. */
Create ;
S3=Dev(US)^3/N-1 ; S4=Dev(US)^4/N-1 $
Calc ; List ; C=N*(Sum(S3)/(6*Sdv(US)^3) + Sum(S4)/(24*Sdv(US)^4)) $
/* Below find the
critical value for the Chi-Squared distribution for 2 degrees of freedom.
Compare this to the test statistic above.*/
Calc ; List ;
Ctb(.95,2) $
/* Below test the
exact significance level of the normality test above using the Chi-Squared
distribution. */
Calc ; List ;
Cprob=1-Chi(C,2) $
/* Now lets compute
the mean of US using least squares. Note that this approach does not enable you
to obtain the variance.*/
Minimize ;
labels=mu ; Start=130 ; Fcn=(US-mu)^2 ; Alg= Newton $
/*You could also
use the regression procedure to do this as follows. This approach allows you to
obtain the variance (S.D. squared), but there is no standard error on the
variance estimate. */
Regress ; Lhs=US ;
Rhs=One $
/* Now lets compute
the mean and variance of US using maximum likelihood (MLE). */
Maximize ;
labels=mu,Sig2 ; Start=130,6000 ; Fcn=-log(sqr(2*pi*Sig2))-(1/(2*Sig2))*(US-mu)^2
; Alg= Newton $
/* The MLE of the
variance (and standard deviation) is biased. We can get the unbiased estimate
by multiplying the variance by n/n-k */
Calc ; List ;
Sig2Unb= Sig2*n/(n-1) $
/*Note that the
printout gives the standard errors, which is just the standard deviations of
the respective sampling distributions. This information is also contained in
the Covariance matrix of estimates, which is the negative of the inverse of the
Hessian. Let's print the Covariance matrix. Verify that the square root of the
diagonal of this matrix contains the standard errors from the printout.*/
Matrix ; list ;
Varb $
/* Now let's test
some hypotheses using some of the procedures discussed in class. First, let's
do a t test that the true mean is 120 using the regression procedure above. */
Regress ; Lhs=US ;
Rhs=one $
Calc ; List ; Tstat=(b(1)-120)/sqr(Varb(1)) ; Tprob=1-Tds(Tstat,N)$
/*We can do the
same thing using a Wald statistic from within the regression procedure. The
Wald is the square of the preceding t statistic. Verify this for yourself. */
Regress ; Lhs=US ;
Rhs=one ; Wald: b(1)=120 $
/* Alternatively,
we can use the Wald procedure separately. */
Regress; Lhs=US ;
Rhs=one $
Wald ; Fn1=b_one-120 $
/* Now, a Wald statistic
for the null that the true mean is 120 can also be done using the maximum
likelihood procedure. Note that we are saving the log likelihood from this for
later use. Note also, that as the course proceeds you will see that there are
much easier ways to do the Wald test. */
Maximize ;
labels=mu,Sig2 ; Start=130,6000 ;
Fcn=-log(sqr(2*pi*Sig2))-(1/(2*Sig2))*(US-mu)^2
; Alg= Newton $
Calc ; list ;
LogLU=LOGL $
Matrix ; list ; Brst=B(1)-120 $
MATRIX ; LIST ; VARBrst=VARB(1,1) $
Matrix ; list ; Waldstat=Brst'*<VARBrst>*Brst $
Calc ; list ; Cprob=1-Chi(Waldstat,1) $
/* Now perform
restricted estimation in which we restrict the mean to 120.*/
Maximize ;
labels=mu,Sig2 ; Start=120,6000 ;
Fcn=-log(sqr(2*pi*Sig2))-(1/(2*Sig2))*(US-mu)^2
; Alg= Newton ; Fix=mu $
Calc ; list ;
LogLR=LOGL $
/* We can now do a
likelihood ratio test with the saved values of the log likelihood function from
the preceding two estimations.*/
Calc ; List ;
LLRatio=-2*(LogLR-LogLU) ; Cprob=1-Chi(LLRatio,1) $
/* We can
also now do a LaGrange Multiplier test that the true mean is 120. Note again
that as the course proceeds you will see that there are other ways to do a
LaGrange Multiplier test. In this version we are using the BHHH estimator of
the asymptotic covariance matrix. */
Create ;
gmu=(1/Sig2)*(US-mu) ; gsig2=(-1/(2*Sig2))+((US-mu)^2/(2*Sig2^2)) $
Namelist ; G=gmu,gsig2 $
Matrix ; list ; LMstat=1'G*<G'G>*G'1 $
Calc ; list ; Cprob=1-Chi(LMstat,1) $
/* Note that it is
possible to get different results, depending on which of the three tests is
selected. Thus, the LM test above rejects the null that the true mean is 120,
while the others don't. This is partially also a result of using the BHHH
estimator of the asymptotic covariance matrix. */
Delete ; * $