Friday, July 4, 2008

Critical values for the Student's t distribution

Confidence intervals for OLS regression models require to look up values for the Student's t distribution. The following GAMS include file will implement such a table in GAMS readable format.



Example:

set i /case1*case116/
k0 /
constant 'constant term in regression'
povrate 'poverty level'
urb 'not used'
famsize 'average household size'
unemp 'percentage unemployment rate'
highschl 'percentage of population age 25 and over with high school degree only'
college 'percentage of population age 25 and over that completed 4 or more years of college'
medinc 'median household income'
D90 'dummy: one for the 1990 Census and zero for the 1980 Census'
/
k1(k0) 'data used' /povrate,famsize,unemp,highschl,college,medinc,D90/
;

*------------------------------------------------------------------------------
* input data from Ramanthan (2002, Data 7-6, p. 653)
*------------------------------------------------------------------------------

table data(i,k0) '-- input data from Ramanthan (2002, Data 7-6, p. 653)'
$include poverty.inc
;
display data;


*------------------------------------------------------------------------------
* critical values t distribution
*------------------------------------------------------------------------------

$include tc.inc

*------------------------------------------------------------------------------
* create some summary statistics
*------------------------------------------------------------------------------

parameter summary(k1,*) '-- summary statistics';
summary(k1,'mean') = sum(i,data(i,k1))/card(i);
summary(k1,'min') = smin(i,data(i,k1));
summary(k1,'max') = smax(i,data(i,k1));
summary(k1,'stdev') = sqrt[sum(i,sqr[data(i,k1)-summary(k1,'mean')])/(card(i)-1)];
summary(k1,'coeffvar') = summary(k1,'stdev')/summary(k1,'mean');
display summary;

*------------------------------------------------------------------------------
* linear regression using OLS
*------------------------------------------------------------------------------

set k(k0) 'regression coefficients'
/constant,famsize,unemp,highschl,college,medinc,D90/;
data(i,'constant') = 1;

variables
beta(k) 'regression coefficients'
sse 'sum of squared errors'
;
equations
dummyobj 'dummy objective'
fit(i) 'fit linear equations'
;

dummyobj.. sse =n= 0;
fit(i).. data(i,'povrate') =e= sum(k, beta(k)*data(i,k));

model ols /dummyobj,fit/;

option lp=ls;
solve ols using lp minimizing sse;

parameter ols_se(k) 'standard errors';
ols_se(k) = beta.m(k);

set ival 'confidence interval' /lo,up/;
scalar ndf 'degrees of freedom';
ndf = card(i) - card(k);
scalar alpha 'significance level' /0.025/;
scalar qt 'critical value';
qt = sum((df,prob)$(dfval(df)=ndf and probval(prob)=0.025), tc(df,prob));
display ndf,alpha,qt;

parameter ols_conf_ival(k,ival);
ols_conf_ival(k,'lo') = beta.l(k) - qt*ols_se(k);
ols_conf_ival(k,'up') = beta.l(k) + qt*ols_se(k);
display ols_se,ols_conf_ival;


Example output:

 =======================================================================
Least Square Solver
Erwin Kalvelagen, November 2004, October 2006
=======================================================================

Parameter Estimate Std. Error t value Pr(>|t|)
beta('constant') 0.21659E+02 0.55303E+01 0.39164E+01 0.15708E-03 ***
beta('famsize') 0.18042E+01 0.11617E+01 0.15531E+01 0.12329E+00
beta('unemp') 0.76467E-01 0.59044E-01 0.12951E+01 0.19803E+00
beta('highschl') -0.20135E+00 0.39135E-01 -0.51450E+01 0.11914E-05 ***
beta('college') 0.21313E-01 0.45803E-01 0.46532E+00 0.64263E+00
beta('medinc') -0.41557E+00 0.46677E-01 -0.89030E+01 0.13484E-13 ***
beta('D90') 0.85045E+01 0.10434E+01 0.81508E+01 0.66416E-12 ***
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

Estimation statistics:
Cases: 116 Parameters: 7 Residual sum of squares: 0.32146E+03
Residual standard error: 0.17173E+01 on 109 degrees of freedom
Multiple R-squared: 0.74583E+00 Adjusted R-squared: 0.73183E+00
F statistic: 0.53307E+02 on 6 and 109 DF, p-value: 0.00000E+00

DLL version: _GAMS_GDX_237_2007-01-09
GDX file: ls.gdx


---- 1276 PARAMETER ndf = 109.000 degrees of freedom
PARAMETER alpha = 0.025 significance level
PARAMETER qt = 1.982 critical value

---- 1281 PARAMETER ols_se standard errors

constant 5.530, famsize 1.162, unemp 0.059, highschl 0.039, college 0.046, medinc 0.047
D90 1.043


---- 1281 PARAMETER ols_conf_ival

lo up

constant 10.698 32.619
famsize -0.498 4.107
unemp -0.041 0.193
highschl -0.279 -0.124
college -0.069 0.112
medinc -0.508 -0.323
D90 6.436 10.572

No comments:

Post a Comment