*! version 1.1.9 GA/PR 13Feb987   STB-42 sg79
program define gamplot
version 5.0
/*
	Plotting program for use after gamfit
*/
local varlist "required existing min(1) max(2)"
local if "opt"
local in "opt"
local options "LEvel(real $S_level) noCONF noPRES ABS(real 1e15) *"
parse "`*'"
if "$S_E_fam"=="cox" {
	local pres "nopres"
}
parse "`varlist'", parse(" ")
local x=substr("`1'",1,6)
if "`2'" != "" {
	local xvar `2'
}
else local xvar `1'
quietly if "`conf'"!="noconf" {
	local z=invnorm((1+`level'/100)/2)
	tempvar top bot
	gen `top'=s_`x'+`z'*e_`x'
	gen `bot'=s_`x'-`z'*e_`x'
	local pen1 "66"
	local sym1 "ii"
	local con1 "ss"
}
quietly if "`pres'"!="nopres" {
	tempvar partres
	gen `partres'=r_`x'
	lab var `partres' "GAM partial residuals for `x'"
	local pen2 "2"
	local sym2 "o"
	local con2 "."
/*
	Option for excluding points which destroy the scaling
*/
	count if abs(s_`x'-r_`x')>`abs'
	local excl=_result(1)
	if `excl'>0 {
		if `excl'>1 { local s "s" }
		noi di in bl "[`excl' point`s' excluded from plot]"
		replace `partres'=. if abs(s_`x'-r_`x')>`abs'
	}
}
local pen "pen(3`pen1'`pen2')"
local sym "s(i`sym1'`sym2')"
local con "c(s`con1'`con2')"
graph s_`x' `top' `bot' `partres' `xvar' `if' `in', /*
 */ `sym' `con' sort `pen' `options'
end