' plot joint confidence region of two OLS parameters
' replicates Greene (1993,p.191)
' for version 4
' 12/20/2000 h

' include subroutine
include drawEllipse.prg

' load workfile
%data = @runpath + "greene6_2"
load "{%data}"

' estimate equation by OLS
equation eq1.ls y x1 x2 x3 x4 x5

' get c(2) and c(3)
vector(2) beta
beta(1) = eq1.c(2)
beta(2) = eq1.c(3)

' get covariance martrix of c(2) & c(3)
sym(2,2) binv
binv(1,1) = eq1.@cov(2,2)
binv(1,2) = eq1.@cov(2,3)
binv(2,2) = eq1.@cov(3,3)
' and invert
binv = @inverse(binv)

' call the subroutine to plot the joint confidence ellipse
!fcv95 = @qfdist(0.95, 2, eq1.@regobs-eq1.@ncoef)
call drawEllipse(beta, binv, 2*!fcv95, "gra1")	' 3rd arg is critical value

' edit legend and title to graph
gra1.setelem(1) legend(b_2)
gra1.setelem(2) legend(b_3)
gra1.addtext(t) Joint vs Individual 0.95 Confidence Region

' add individual 0.95 region as shades
!b_low = eq1.c(2)-2*eq1.@stderrs(2)
!b_upp = eq1.c(2)+2*eq1.@stderrs(2)
gra1.draw(shade,bottom) !b_low !b_upp
gra1.draw(dashline,bottom) !b_low
gra1.draw(dashline,bottom) !b_upp

!b_low = eq1.c(3)-2*eq1.@stderrs(3)
!b_upp = eq1.c(3)+2*eq1.@stderrs(3)
gra1.draw(shade,left) !b_low !b_upp
gra1.draw(dashline,left) !b_low
gra1.draw(dashline,left) !b_upp

show gra1
