*! version 1.0.0 07jul1996 program define hlu version 4.0 local options "Level(int $S_level)" if substr("`1'",1,1)=="," | "`1'"=="" { if "$S_E_cmd"!="hlu" { error 301 } parse "`*'" } else { local varlist "req ex min(2)" local if "opt" local in "opt" local options "`options' noLog" parse "`*'" tempfile HLUITR tempvar X tempname lest if "`log'"!="" { local log "*" } else local log "noisily di" preserve quietly { keep `varlist' `if' `in' noisily confirm new var _iter save `HLUITR' , replace `log' in gr "Iteration 0: rho = " in ye "0.0000" regress `varlist' local rhol = 0.0 local ssel = _result(4) use `HLUITR', clear `log' in gr "Iteration 1: rho = " in ye "0.9999" local rhoh = .9999 gen _iter = 1 - `rhoh' parse "`varlist'", parse(" ") local depv = "`1'" while "`1'"!="" { gen float `X'=`1'-(`rhoh')*`1'[_n-1] drop `1' rename `X' `1' mac shift } regress `varlist' _iter, hascons local sseh = _result(4) local rhom = (`rhoh'+`rhol')/2 local i = 2 while `i'<=15 { use `HLUITR', clear `log' in gr "Iteration `i': rho = " /* */ in ye %6.4f `rhom' gen _iter = 1 - `rhom' parse "`varlist'", parse(" ") while "`1'"!="" { gen float `X'=`1'-(`rhom')*`1'[_n-1] drop `1' rename `X' `1' mac shift } regress `varlist' _iter, hascons local ssem = _result(4) capture estimates drop `lest' estimates hold `lest' if `ssel'<=`ssem' & `ssel'<=`sseh' { local rhoh = `rhom' local sseh = `ssem' } else if `sseh'<=`ssem' & `sseh'<=`ssel' { local rhol = `rhom' local ssel = `ssem' } else if `ssel'<=`sseh' { local rhoh = `rhom' local sseh = `ssem' } else { local rhol = `rhom' local ssel = `ssem' } local rhom = (`rhoh'+`rhol')/2 local i = `i'+1 } estimate unhold `lest' global S_E_rho = `rhom' global S_E_cmd "hlu" global S_E_depv = "`depv'" } } if `level'<10 | `level'>99 { local level 95 } noisily di _n in gr "(Hildreth-Lu regression) noisily regress, level(`level') noisily di in gr /* */ " rho |" in ye " " %9.4f $S_E_rho /* */ _n in gr _dup(78) "-" end exit