program xtregkv, rclass byable(recall) sort
	version 6, missing
	syntax [varlist(ts)] [if] [in] [, I(varname)]
	_xt, i(`i')
	local ivar `r(ivar)'
	local tvar `r(tvar)'


qui foreach i in `varlist' {
keep if `i'~=.
if "`if'"~=""{
keep `if'
}
}

tokenize `varlist'
local first `1'
macro shift
local rest `*'
foreach i in `rest' {
egen kontext`i' = mean (`i'), by(`ivar')
}
_rmcoll `rest' kontext*
local xvars `r(varlist)'
xtreg `first' `xvars'
drop kontext*
end