Statalist The Stata Listserver


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

Re: st: easy way to save regressor variable names?


From   Rose Medeiros <rosem@cisunix.unh.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: easy way to save regressor variable names?
Date   Sat, 11 Mar 2006 11:13:36 -0500

Toby,
My answer to your first question will depend on the regression command used. (I say my answer, since someone else may have a better way of doing this.) After you run regress, if covariates are dropped for collinearity, they will appear in the coefficient vector (e(b)), but the coefficient value in the vector e(b) will be zero. For commands like logit, ologit, and mlogit, independent variables dropped for collinearity will not appear in the coefficient vector. So you have to accommodate the particular regression command used. Also note that the constant (_cons) will be in the coefficient vector, so you'll have to remove that as well. Below is some syntax that I've been using to do what you describe (the list of variables is returned as the local macro p_list), it appears to work, but I make no guarantees.
Best,
Rose

* -------- begin example when command is regress -----------
* run regress
local cons "_cons"
matrix define B = get(_b)
local p : colfullnames e(b)
local n = "`s(after)'"
local r : list sizeof n
local clist = " "
forvalues j = 1/`r' {
scalar define c`j' = B[1,`j']
if (c`j'~=0) {
local newpred : word `j' of `p'
local clist : list clist | newpred
}
}
local p_list : list clist - cons
*-------- end example when command is regress -----------

*-------- begin example when command is logit, ologit, or mlogit -----------
* run logit or mlogit
local p : colnames e(b)
local p_list : list p - cons
*-------- end example when command is logit, ologit, or mlogit -----------


Toby Andrew wrote:


Dear all,

I have 2 questions related to saving summary stats from regression analyses:

1) Is there a generic way to access the list of variable names used in a regression such as regress, mlogit & ologit?
The reason i ask is because i am performing many regressions by looping over variables & the list of recorded variables i save
will differ from the *actual* list retained in the analysis if there is collinearity (or i wish to use stepwise sw).

2) is there an "_rc" error message (or equivalent) i can record in the summary postfile results, if the model fails to converge?

Thanks very much,

Toby

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/


--
Rose Anne Medeiros
Department of Sociology / Family Research Laboratory
University of New Hampshire
126 Horton Social Science Center
20 College Road
Durham, NH 03824
U.S.A.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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