*! pangrodev 1.0.0  CFBaum 28May2001
*  generate deviations from constant growth in panel context
program define pangrodev, eclass
version 7.0
syntax varname, Gen(string) [xb]
local togens "deviations from constant growth"
if "`xb'" != "" {
	local togens "predicted growth"
	}
qui tsset
local ivar = r(panelvar)
local timevar = r(timevar)
tempname VV
tempvar lvar pvar
qui gen `lvar' = log(`varlist')
qui tab `ivar',matrow(`VV')
local nvals=r(r)
local j = 1
while `j'<=`nvals' {
 	local val = `VV'[`j',1]
 	local vals "`vals' `val'"
 	local j=`j'+1
	}
qui gen double `gen'=.
local xc 0
local tbar 0
local rsqr 0
foreach v of local vals {
summ `lvar' if `ivar'==`v',meanonly
if r(N)>2 {
	qui regress `lvar' `timevar' if `ivar'==`v'
	capt drop `pvar'
	qui predict double `pvar' if e(sample),xb
	qui replace `gen' = exp(`pvar') if e(sample)
	if "`xb'" =="" {
		qui replace `gen' = `varlist'-`gen' if e(sample)
		}
	local xc = `xc' + 1
	local tbar = `tbar' + e(N)
	local rsqr = `rsqr' + e(r2)
	}
}
local tbar = int(100*`tbar' / `xc')/100.0
local rsqr = int(1000*`rsqr' / `xc')/1000.0
di in gr _n "`gen' : `togens' for `xc' of `nvals' units"
di in gr "tbar = `tbar'    rsq-bar = `rsqr'"
exit
end