Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: hireg help

From   "Austin Nichols" <>
Subject   Re: st: hireg help
Date   Fri, 18 May 2007 11:15:59 -0400

For why the SSC module -hireg- does not work as expected, you may wish
to email the author:
Paul H. Bern, Syracuse University
(taken from the help file) though he may want a reproducible example
of its not working beginning with e.g. -sysuse auto- as well.

I've noticed that questions on stepwise regression or the like
occasionally go unanswered on Statalist, perhaps because the practice
is inadvisable (i.e. don't do it!).

After a quick look, -hireg- seems to have some minor mistakes in the
code--e.g. it reports obs not used when option -nomiss- is specified
without reference to [if] and [in] restrictions--but I cannot easily
see the source of your reported error.  As to the statistical validity
ot the output, I doubt I would ever use it myself... am I repeating

But here's another version that may work for you (caveat emptor), if
you save the code between the horizontal lines below to a file
"hireg2.ado" in your Stata's search path (e.g. /ado/plus/h). In my
version, groups of variables to be added are specified in quotes, not
parentheses, and I took out the options -xi- and -regopts- but options
for the regressions can still be specified after a comma, and I added
the option -quietly- to suppress regression output.  For a demo, try:
sysuse auto, clear
hireg pr (mpg length turn) (disp for wei)
hireg2 pr "mpg length turn" "disp for wei", q
hireg2 pr "" "mpg length turn" "disp for wei", q
hireg2 pr "mpg" "wei rep78" if for==1, q
hireg2 pr "mpg" "wei rep78" if for==1, nomi q

prog hireg2
*! based on -hireg- version 2.1 22JUL2005
syntax anything [if] [in] [aw pw iw fw] ,  [NOMiss Quietly *]
if "`nomiss'"!="" {
local varlist: subinstr local anything `"""' "", all
marksample touse, zero
qui count `if' `in'
local maxn=r(N)
loc cif=cond(`"`if'"'=="","if !`touse'",`"`if' & !`touse'"')
qui count `cif' `in'
di "NoMissing option specified, " _c
di "`r(N)' of `maxn' observations not used."
else {
local varlist: word 1 of `anything'
marksample touse
gettoken depvar anything: anything
local n
local rhs
foreach addrhs in `anything' {
local n=`n'+1
local rhs `rhs' `addrhs'
`quietly' reg `depvar' `rhs' if `touse' [`weight' `exp'], `options'
local r2_`n' =e(r2)
local df`n'   =e(df_m)
local dfr`n'  =e(df_r)
local mss`n'   =e(mss)
local ssr`n'  =e(rss)
local f`n'   =e(F)
if `n'>1 {
 local i=`n'
 local j = `i' - 1
local fc`j'=((`mss`i''-`mss`j'')/(`df`i'' - `df`j''))*(`dfr`i''/`ssr`i'')
 local rc`j' = `r2_`i'' - `r2_`j''
 local dfc`j' = `df`i''-`df`j''
 di in gr "R-Square Diff. Model `i' - Model `j' = " _c
 di in ye %5.3f `rc`j''  in gr "   F(" `df`j'' ","`dfr`i'' ") = " _c
 di in ye %6.3f `fc`j'' in gr "  p = " _c
 di in ye %5.3f 1-F(`dfc`j'',`rc`j'',`fc`j'')
di in gr "Model" _col(8) "R2" _col(15) " F(df)" _col(35) "p" _c
di _col(45) "R2 change" _col(55) " F(df) change" _col(75) "p"
di _col(4) "1:" in ye _col(8) %5.3f `r2_1' _c
di _col(15) %6.3f `f1' "(" `df1' "," `dfr1' ")" _c
di _col(35) %5.3f 1-F(`df1',`dfr1',`f1')
forvalues m=1 /`= `n'-1'{
 local ii = `m' + 1
 di in gr _col(4) "`ii':"   _c
 di in ye _col(8) %5.3f `r2_`ii'' _c
 di _col(15)  %6.3f `f`ii'' "(" `df`ii'' "," `dfr`ii'' ")"  _c
 di _col(35) %5.3f 1-F(`df`ii'',`dfr`ii'',`f`ii'') _c
 di _col(45) %5.3f `rc`m'' _c
 di _col(55) %6.3f `fc`m'' "(" `dfc`m'' "," `dfr`ii'' ")" _c
 di _col(75) %5.3f 1-F(`dfc`m'',`dfr`m'',`fc`m'')

On 5/18/07, Megan McHugh <> wrote:
Dear listserv members,

I am in a bit of a jam and I was hoping someone might be able to provide some guidance.  When I use the command...

"hireg dollarmargin (EDadmit surgical anyoutlier ortho cardiac surgcardiac surg ortho) (resbed DSH beds public forprofit levelone)"

the last 3 variables (public, forprofit and levelone) are omitted from the second model.  No matter what variables I place at the end of the command, they are dropped from the output (i.e., multicollinearity is not the problem).  It seems to work fine when I trim down the number of variables in the first model, but, of course, I need the output for all the variables.  I'm using Stata 8.

Have you encountered this problem before?  Does anyone have any advice?  Someone posed this same question to the listserv in 2005, but it was not answered.

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index