*! version 1.4.4  13mar2000
program define xtreg, eclass
* touched by jwh
	version 6
	if replay() {
		if `"`e(cmd)'"'==`"xtreg"' {
			xtreg_`e(model)' `0'
			exit `e(rc)'
		}
		else if `"`e(cmd2)'"' == "xtreg" {
			`e(cmd)' `0'
			exit `e(rc)'
		}
		error 301
		/*NOTREACHED*/
	}
	qui q born
	local afwgt = cond($S_1<14679, "aw", "fw")

	syntax varlist [if] [iw `afwgt' pw] [, BE FE RE MLE PA GEE * ]

	if "`gee'" != "" { local pa "pa " }

	if ("`be'"!="")+("`fe'"!="")+("`re'"!="")+("`pa'"!="")>1 {
		di in red "choose only one of be, fe, re, or pa"
		exit 198
	}

	if `"`be'"'!=`""' | `"`fe'"'!=`""' {
		if `"`mle'"'!=`""' | `"`pa'"'!=`""' { error 198 }
	}
	else {
		if `"`mle'"'!=`""' & `"`pa'"'!=`""' { error 198 }
	}

	if `"`be'"'!=`""' {
		if "`weight'" != "" {
			di in red "`weight' not allowed with be model"
			exit 101
		}
		xtreg_be `varlist' `if' /* [`weight'`exp'] */, `options'
	}
	else if `"`fe'"'!=`""' {
		if "`weight'" != "" {
			di in red "`weight' not allowed with fe model"
			exit 101
		}
		xtreg_fe `varlist' `if' /* [`weight'`exp'] */, `options'
	}
	else {
		if `"`mle'"' == `""'  & `"`pa'"' == `""' {
			if "`weight'" != "" {
				di in red "`weight' not allowed with re model"
				exit 101
			}
			xtreg_re `varlist' `if' /* [`weight'`exp']*/ , `options'
			exit
		}
		if `"`mle'"' == `""' {
			xtgee `varlist' `if' [`weight'`exp'], `options'
			est local cmd2 "xtreg"
			est local model "pa"
			exit
		}
		else {
			xtreg_ml `varlist' `if' [`weight'`exp'], `options'
		}
	}
	exit `e(rc)'
end