' subroutine to reformat regresion output
' revised for version 4.0 (10/20/2000 h)
'
'	   eq1: name of equation object
'	  tab1: name of table object for output
'	format: digits after decimal to display
'
subroutine regtab(equation eq1, table tab1, scalar format)

' number of estimated parameters
!ncoef =eq1.@ncoef
' number of observations in estimation sample
!obs=eq1.@regobs

' create temporary table with eviews estimation output
freeze(temp_table) eq1.results

' declare a new table
table(1,4) tab1
' format table
setcolwidth(tab1, 1, 19)
setcolwidth(tab1, 2, format+4)
setcolwidth(tab1, 3, 19)
setcolwidth(tab1, 4, format+4)

' get original header information
!line = 1
while temp_table(!line, 2) <> "Coefficient"
	setcell(tab1, !line, 1, temp_table(!line, 1), "l") 
	!line = !line +1
wend

setline(tab1, !line-1)
setcell(tab1, !line, 1, "Variable", "c" )
setcell(tab1, !line, 2, "Estimate","r")
setcell(tab1, !line, 3, "Estimate","r")
setcell(tab1,!line+1,2, "(s.e.)","r")
setcell(tab1,!line+1,3, "(t-stat)","r")
!line = !line + 2
setline(tab1, !line)
!line = !line + 1
!vline = !line 

' fill all of the coefficients and standard errors 
' (or t-statistics)
for !i = 1 to !ncoef
	' get variable name
	%variable = temp_table(!vline-1, 1)
	
	' write coefficients
	setcell(tab1, !line, 1, %variable, "c")
	!vline = !vline + 1

	' write coefficients
	!est=eq1.@coefs(!i)
	setcell(tab1, !line, 2, !est, "r", format )
	setcell(tab1, !line, 3, !est, "r", format )
	!line = !line + 1
	
	' compute statistics
	!se = sqr(eq1.@covariance(!i, !i))
	!tstat = !est/!se
	!tprob = @tdist(!tstat, !obs-!ncoef)
	
	' write standard errors in parenthesis
	setcell(tab1, !line, 2, !se, "r", format )
	%str_se = tab1(!line, 2)
	%str_se = "(" + %str_se + ")"
	tab1(!line, 2) = %str_se

	' write t-statistic output
	setcell(tab1, !line, 3, !tstat, "r", format )
	%str_t = "(" + tab1(!line, 3) + ")"
	' mark if significant
	if !tprob < .01 then
		%str_t = "**" + %str_t
	else 
		if !tprob < .05 then
			%str_t = "*" + %str_t
		endif
	endif
	tab1(!line, 3) = %str_t

	' increment line counter
	!line = !line + 1
next

setline(tab1, !line)
!line = !line + 1

' original results at bottom of table
setcell(tab1, !line, 1,  "R-squared", "l") 
setcell(tab1, !line, 2, eq1.@r2, "r", format )
setcell(tab1, !line, 3,  "  Mean dependent var", "l")
setcell(tab1, !line, 4, eq1.@meandep, "r", format )
!line = !line + 1

setcell(tab1, !line, 1, "Adjusted R-squared", "l")
setcell(tab1, !line, 2, eq1.@rbar2, "r", format )
setcell(tab1, !line, 3, "  S.D. dependent var", "l")
setcell(tab1, !line, 4, eq1.@sddep, "r", format )
!line = !line + 1

setcell(tab1, !line, 1,  "S.E. of regression", "l")
setcell(tab1, !line, 2,  eq1.@se, "r", format )
setcell(tab1, !line, 3,  "  Akaike info criterion", "l")
setcell(tab1, !line, 4, eq1.@aic, "r", format )
!line = !line + 1

setcell(tab1, !line, 1, "Sum squared resid", "l")
setcell(tab1, !line, 2, eq1.@ssr, "r", format )
setcell(tab1, !line, 3, "  Schwarz criterion", "l")
setcell(tab1, !line, 4, eq1.@schwarz, "r", format )
!line = !line + 1

setcell(tab1, !line, 1, "Log likelihood", "l")
setcell(tab1, !line, 2, eq1.@logl, "r",  format )
setcell(tab1, !line, 3, "  F-statistic", "l")
setcell(tab1, !line, 4, eq1.@f, "r", format )
!line = !line + 1

setcell(tab1, !line, 1, "Durbin-Watson stat", "l")
setcell(tab1, !line, 2,  eq1.@dw, "r", format)
setcell(tab1, !line, 3, "  Prob(F-statistic)", "l")
setcell(tab1, !line, 4, @fdist(eq1.@f,(!ncoef-1),(!obs-!ncoef)), "r", format)
!line = !line + 1
setline(tab1, !line)

endsub
